0

我有这段代码,允许用户在某些单元格中输入图表参数并动态创建图表。在两个垂直 (y) 轴和一个共享的水平 (x) 轴上允许有多个系列(最多四个)。图表通常是列和线的混合,并且数据范围的长度不等。我有这样添加系列的代码(我会尽量坚持我认为相关的代码)

 seriesCount = 1
 If hasSeries1 = True Then
   ActiveChart.SeriesCollection.NewSeries
   ActiveChart.SeriesCollection(seriesCount).Name = .Cells(2, 6) & " " & axisside1
   ActiveChart.SeriesCollection(seriesCount).ChartType = chartType1
   ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup1
   ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle1
   ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor1
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth1
   ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor1
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine1
   ActiveChart.SeriesCollection(seriesCount).XValues = dates1
   ActiveChart.SeriesCollection(seriesCount).Values = dataset1
   seriesCount = seriesCount + 1
 End If
 If hasSeries2 = True Then
   ActiveChart.SeriesCollection.NewSeries
   ActiveChart.SeriesCollection(seriesCount).Name = .Cells(3, 6) & " " & axisside2
   ActiveChart.SeriesCollection(seriesCount).ChartType = chartType2
   ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup2
   ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle2
   ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor2
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth2
   ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor2
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine2
   ActiveChart.SeriesCollection(seriesCount).XValues = dates2
   ActiveChart.SeriesCollection(seriesCount).Values = dataset2
   seriesCount = seriesCount + 1
 End If
 If hasSeries3 = True Then
   ActiveChart.SeriesCollection.NewSeries
   ActiveChart.SeriesCollection(seriesCount).Name = .Cells(4, 6) & " " & axisside3
   ActiveChart.SeriesCollection(seriesCount).ChartType = chartType3
   ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup3
   ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle3
   ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor3
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth3
   ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor3
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine3
   ActiveChart.SeriesCollection(seriesCount).XValues = dates3
   ActiveChart.SeriesCollection(seriesCount).Values = dataset3
   seriesCount = seriesCount + 1
 End If
 If hasSeries4 = True Then
   ActiveChart.SeriesCollection.NewSeries
   ActiveChart.SeriesCollection(seriesCount).Name = .Cells(5, 6) & " " & axisside4
   ActiveChart.SeriesCollection(seriesCount).ChartType = chartType4
   ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup4
   ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle4
   ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor4
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth4
   ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor4
   ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine4
   ActiveChart.SeriesCollection(seriesCount).XValues = dates4
   ActiveChart.SeriesCollection(seriesCount).Values = dataset4
 End If

这就是问题所在:图表只显示了它应该显示的部分数据。当我右键单击数据系列,点击Select Data并选择Edit时,正确的系列(x 和 y)会突出显示,但显示的是应该存在的截断子集。

这是我所看到的示例

我的图表

这是浅蓝色列的一些数据

12/30/2005       307%
1/31/2006        302%
2/28/2006        248%
3/31/2006        262%
4/28/2006        285%
5/31/2006        256%
...              ...
...              ...
...              ...
6/30/2014        147%

请注意,从 2005 年 12 月 30 日开始,该数据应该如何显示在图表上,但它是从 2013 年 11 月 30 日开始的(尽管这些值似乎是正确的,307%、302% 等)。就好像 excel 强制第二个和第三个数据系列的长度与第一个相同。第一个是正确的图表。

4

1 回答 1

0

我认为您没有使用 XY 图表,因此每个系列都必须具有相同的标签(Xvalues = 您的日期)。这意味着您需要创建一个包含所有日期的唯一日期集,并将其(作为 Xvalues)分配给第一个系列。

于 2014-09-09T06:40:23.760 回答