代码抛出System.ArgumentOutOfRangeException
,因为该系列似乎不存在。当我尝试调试单步时,再次添加该系列,因为该系列已存在而抛出错误...
For Each row As DataRow In dt.Rows
Chart1.Series.Add(row("Counter"))
Chart1.Series(i).ChartType = Charting.SeriesChartType.StackedColumn
Chart1.Series(i).Label = 1
Dim dp As Charting.DataPoint = New Charting.DataPoint()
Dim sDay As String = row("Tag")
If i = 0 Then
sDayRowBefore = sDay
Else
If sDayRowBefore <> sDay Then
iSeriesIndex = iSeriesIndex + 1
End If
End If
dp.XValue = iSeriesIndex
Chart1.Series(i).IsXValueIndexed = True
dp.AxisLabel = row("Tag")
dp.SetValueY(1)
dp.Color = row("ItemFarbe")
Chart1.Series(row("Counter")).Points.Add(dp)
sDayRowBefore = sDay
Chart1.DataManipulator.Filter(Charting.CompareMethod.EqualTo, 0, Chart1.Series(i))
i = i + 1
Next
当我再次为另一个数据集使用相同的图表时,才会抛出错误。 在生成图表之前,我清除了系列,点和图表区域。
For Each var As Charting.Series In Chart1.Series
var.Points.Clear()
Next