区域图的一部分未填写vba

时间:2017-03-15 14:01:32

标签: excel vba excel-vba charts

我试图生成区域图表,其中绿色表示超过阈值的值,而红色值表示值。我能够生成图表,但我的问题是我没有得到连续的图形(它们总是在不同颜色值之间出现间隙空间,即使单元格中有一个数字代表图中的差距)。 图表的示例代码:

Sub x_Graph()

'Define Chart
Dim c As Chart
Set c = ActiveWorkbook.Charts.Add
Set c = c.Location(Where:=xlLocationAsObject, Name:="RRL")
With c
.ChartType = xlArea
.HasTitle = True
.ChartTitle.Text = Sheets("Control Data").Range("C4").Value
End With

'Delete pre-defined series
Do Until ActiveChart.SeriesCollection.Count = 0
ActiveChart.SeriesCollection(1).Delete
Loop

With c
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = Sheets("PD").Range("AN$34:AY$34")
.SeriesCollection(1).Values = Sheets("PD").Range("AN$40:AY$40")
.SeriesCollection.NewSeries
.SeriesCollection(2).XValues = Sheets("PD").Range("AN$34:AY$34")
.SeriesCollection(2).Values = Sheets("PD").Range("AN$41:AY$41")

'Name series and format size

c.SeriesCollection(1).Name = "HU (days/month)"
c.SeriesCollection(2).Name = "LU (days/month)"
.Parent.Width = 700
.Parent.Height = 450

End With

c.SeriesCollection(1).Select
With Selection
.Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
End With

c.SeriesCollection(2).Select
With Selection
.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With

'Format fonts
c.Legend.Select
    With Selection.Format.TextFrame2.TextRange.Font
        .BaselineOffset = 0
        .Size = 14
        .Name = "Arial"
        End With
c.Axes(xlValue).Select
With Selection.TickLabels.Font
     .Size = 14
     .Name = "Arial"
   End With
c.Axes(xlCategory).Select
With Selection.TickLabels.Font
     .Size = 14
     .Name = "Arial"
   End With

End Sub

图表如下:

红色和绿色区域之间存在间隙,即使单元格中有数据。

输入数据采用以下格式: 绿色是由" Good"系列和红色是从" Bad"

创建的

背景代码:

任何人都知道可以做些什么?

非常感谢提前 FN

0 个答案:

没有答案