在我正在构建的测试应用中,我在尝试绘制图表时遇到了此错误。在尝试绘制甘特图时,我有一些伪随机生成的数据会导致我的测试应用程序崩溃...
System.ArgumentOutOfRangeException未处理HResult = -2146233086 消息=索引超出范围。必须是非负的且小于 集合的大小。参数名称:index ParamName = index Source = mscorlib StackTrace:at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument 参数,ExceptionResource资源)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)在Steema.TeeChart.Chart.DrawAllSeries(Graphics3D g)at at Steema.TeeChart.Chart.InternalDraw(Graphics g,Boolean noTools)at Steema.TeeChart.Chart.InternalDraw(Graphics g)at Steema.TeeChart.TChart.Draw(图形g)at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16层)在System.Windows.Forms.Control.WmPaint(Message& m)at System.Windows.Forms.Control.WndProc(Message& m)at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr) hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)InnerException:
在TeeChart Gantt图表绘制逻辑中似乎有所下降。
我的项目在这里: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?
任何关于绕过它的想法或建议都会非常感激。
答案 0 :(得分:0)
这是您的代码中的错误,可以使用以下简单的代码段重现:
SELECT name_status
FROM(SELECT * FROM tbl1, tbl2 WHERE tbl2.name_status
REGEXP concat(tbl1.name,"_",tbl1.status)) as temp
当循环到达其最后一次迭代(i = 9)时, NextTasks [9] 被设置为10,一个不存在的索引(系列范围从0到9)以及导致索引超出范围错误。解决方案是确保永远不会分配索引,例如:
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;
}
您的代码中的内容将是这样的:
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;
}