TeeChart 甘特图 "System.ArgumentOutOfRangeException was unhandled" 错误

TeeChart Gantt chart "System.ArgumentOutOfRangeException was unhandled" error

在我构建的测试应用程序中,我在尝试绘制图表时遇到了这个错误。我有一些伪随机生成的数据,这些数据在尝试绘制甘特图时使我的测试应用程序崩溃...

System.ArgumentOutOfRangeException was unhandled HResult=-2146233086 Message=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index ParamName=index Source=mscorlib StackTrace: at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at Steema.TeeChart.Styles.Gantt.CopyNextTasks() at Steema.TeeChart.Styles.Gantt.Draw() at Steema.TeeChart.Styles.Series.DrawSeries() at Steema.TeeChart.Chart.DoDraw(Graphics3D g, Int32 First, Int32 Last, Int32 Inc) at Steema.TeeChart.Chart.DrawAllSeries(Graphics3D g) at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools) at Steema.TeeChart.Chart.InternalDraw(Graphics g) at Steema.TeeChart.TChart.Draw(Graphics g) at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException:

它在 TeeChart 甘特图绘制逻辑中似乎很落后。

我的项目在这里:https://www.dropbox.com/sh/haqspd4ux41n2uf/AADkj2H5GLd09oJTW-HrAVr3a?dl=0

如果有人想复制它。

此测试代码曾用于旧版 2.0.2670.26520 TeeChart 的正确执行。

看来我的错误可能与此处描述的错误有关: Exception and endlessly growing designer generated code in InitializeComponent when using Steema TeeChart for .NET 2013 4.1.2013.05280 - What to do?

任何关于绕过它的想法或建议将不胜感激。

这是您的代码中的一个错误,可以使用这个简单的代码片段重现:

  Steema.TeeChart.Styles.Gantt series = new Steema.TeeChart.Styles.Gantt(tChart1.Chart);

  tChart1.Aspect.View3D = false;

  for (int i = 0; i < 10; i++)
  {
    series.Add(DateTime.Now.AddDays(i), DateTime.Now.AddDays(i+5), i, "task " + i.ToString());
    series.NextTasks[series.Count - 1] = series.Count;
  }

当循环到达最后一次迭代 (i = 9) 时,NextTasks[9] 被设置为 10,一个不存在的索引(系列范围从 0到 9),这会导致您得到索引超出范围的错误。解决方案是确保永远不会分配索引,例如:

  const int max = 10;
  for (int i = 0; i < max; i++)
  {
    series.Add(DateTime.Now.AddDays(i), DateTime.Now.AddDays(i+5), i, "task " + i.ToString());
    series.NextTasks[series.Count - 1] = (i < max - 1) ? series.Count : -1;
  }

您的代码中的相同内容如下所示:

      crewSeries.NextTasks[crewSeries.Count - 1] = (crewSeries.Count == crewDataView.Count - 1) ? -1 : crewSeries.Count;