【问题标题】:TeeChart Gantt chart "System.ArgumentOutOfRangeException was unhandled" errorTeeChart 甘特图“System.ArgumentOutOfRangeException 未处理”错误
【发布时间】:2015-10-19 19:56:11
【问题描述】:

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

System.ArgumentOutOfRangeException 未处理 HResult=-2146233086 消息=索引超出范围。必须是非负数且小于 集合的大小。参数名称:index ParamName=index 来源=mscorlib StackTrace:在 System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument 参数,ExceptionResource 资源)在 Steema.TeeChart.Styles.Gantt.CopyNextTasks() 在 Steema.TeeChart.Styles.Gantt.Draw() 在 Steema.TeeChart.Styles.Series.DrawSeries() 在 Steema.TeeChart.Chart.DoDraw(Graphics3D g, Int32 First, Int32 Last, Int32 Inc) 在 Steema.TeeChart.Chart.DrawAllSeries(Graphics3D g) 在 Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools) at Steema.TeeChart.Chart.InternalDraw(Graphics g) 在 Steema.TeeChart.TChart.Draw(Graphics g) at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe) 在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 层)在 System.Windows.Forms.Control.WmPaint(Message& m) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息& m) 在 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?

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

【问题讨论】:

    标签: c# indexoutofboundsexception teechart gantt-chart


    【解决方案1】:

    这是您的代码中的错误,可以使用这个简单的代码 sn-p 重现:

      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;
    

    【讨论】:

    • 感谢纳西斯的回复。我想我明白我哪里错了。每个系列的最后一个任务必须以 -1 结尾。但是,我不确定您的建议是否完全正确。我认为:crewSeries.NextTasks[crewSeries.Count - 1] = (crewSeries.Count == crewDataView.Count - 1) ? crewSeries.Count : -1; 应该是:crewSeries.NextTasks[crewSeries.Count - 1] = (crewSeries.Count &lt;= crewDataView.Count - 1) ? crewSeries.Count : -1;
    • 是的,没错,你是对的。我更正了我的答案:crewSeries.NextTasks[crewSeries.Count - 1] = (crewSeries.Count == crowdDataView.Count - 1) ? -1:船员系列.计数;。重点不是系列中的最后一个任务应该指向 -1,而是应该指向 0 到 crampSeries.Count - 1 范围内的现有索引。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多