缩放后 MSChart 未处理的溢出异常

发布于 2024-09-25 23:14:57 字数 1053 浏览 7 评论 0原文

此问题一年多来, 在 MSChart 论坛上一直没有得到答复。

我在图表上不断遇到溢出异常。我的图表设置如下:

InstrChart.Legends.Clear();
dataArea = InstrChart.ChartAreas.Add("Instr1");
dataArea.AxisX.MajorGrid.Enabled = false;
dataArea.AxisY.MajorGrid.Enabled = false;
dataArea.CursorX.IsUserSelectionEnabled = true;

然后我将添加 12 个系列,每个系列大约 10000 分。

当我缩小以显示每个系列仅 3 或 4 个点时,会发生异常。在我释放鼠标按钮进行缩放后,立即出现以下异常:

System.OverflowException 被捕获   
  消息=“溢出错误。”   
  来源=“系统.绘图”   
  堆栈跟踪:   
     在 System.Drawing.Graphics.CheckErrorStatus(Int32 状态)   

(等 - 请参阅上面的链接以获取完整跟踪。)

我已经删除了图表的所有事件处理程序,但未能阻止最终导致此异常的缩放。我已将图表的 IsUserSelectionEnabled 设置为 false,并从代码中进行缩放,但没有成功。

关于这个问题的任何帮助都会很棒。干杯。

无论图表的其余部分如何配置,只要您缩小“太远”(其含义可能有所不同),就会出现此异常。有几个人报告了这个问题。异常帮助程序表明它位于 System.Drawing.dll 中。

这里有人有任何线索或解决方法吗?

This Question has been languishing un-answered on the MSChart forum for over a year.

I'm continually getting an overflow exception on a chart. I'm setting up my chart as follows:

InstrChart.Legends.Clear();
dataArea = InstrChart.ChartAreas.Add("Instr1");
dataArea.AxisX.MajorGrid.Enabled = false;
dataArea.AxisY.MajorGrid.Enabled = false;
dataArea.CursorX.IsUserSelectionEnabled = true;

I'm then adding 12 series with about 10000 points each.

The exception occurs when I zoom down to show only 3 or 4 point per series. Immediately after I release the mouse button for a zoom I get the following exception:

System.OverflowException was caught   
  Message="Overflow error."   
  Source="System.Drawing"   
  StackTrace:   
     at System.Drawing.Graphics.CheckErrorStatus(Int32 status)   

(etc - see link above for full trace.)

I've removed all event handler for the chart with no luck in stopping zooming from eventuall causing this exception. I've set IsUserSelectionEnabled to false for the chart and done zooming from code with no luck.

Any help on this issue would be great. Cheers.

This exception appears to occur anytime you zoom down "too far" (the meaning of which may vary), regardless of how the rest of the chart is configured. Several people have reported this issue. The exception helper indicates that it's in System.Drawing.dll.

Anyone here have any clues or workarounds?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

清醇 2024-10-02 23:14:58

我今天遇到了同样的问题,错误地将缩放设置为相同的开始值和结束值。

chartarea.AxisX.ScaleView.Zoom(chartarea.CursorX.SelectionStart, chartarea.CursorX.SelectionStart); // second argument should have been chartarea.CursorX.SelectionEnd

然后我尝试了以下实验:

chartarea.AxisX.ScaleView.Zoom(chart.CursorX.SelectionStart, chartarea.CursorX.SelectionStart + 0.00000001); // crash
chartarea.AxisX.ScaleView.Zoom(chart.CursorX.SelectionStart, chartarea.CursorX.SelectionStart + 0.0000001);  // no crash

您的数据点是否可能非常接近,以至于起点和终点之间的距离低于上面观察到的阈值?我建议您尝试将时间值乘以 100 或 1000,看看问题是否消失。

消除此问题的另一种方法是在 ScaleView 上设置 MinSize。

chartarea.AxisX.ScaleView.MinSize = 0.0001; // something bigger than 0.0000001 works for me

I encountered the same problem today when mistakenly setting the zoom with identical start and end values.

chartarea.AxisX.ScaleView.Zoom(chartarea.CursorX.SelectionStart, chartarea.CursorX.SelectionStart); // second argument should have been chartarea.CursorX.SelectionEnd

I then tried the following as an experiment:

chartarea.AxisX.ScaleView.Zoom(chart.CursorX.SelectionStart, chartarea.CursorX.SelectionStart + 0.00000001); // crash
chartarea.AxisX.ScaleView.Zoom(chart.CursorX.SelectionStart, chartarea.CursorX.SelectionStart + 0.0000001);  // no crash

Is it possible that your data points are so close together that the distance between your start and end point is below the threshold observed above? I would recommend you try multiplying your time values by 100 or 1000 and see if the problem disappear.

Another way to eliminate this problem is to set the MinSize on ScaleView.

chartarea.AxisX.ScaleView.MinSize = 0.0001; // something bigger than 0.0000001 works for me
拥有 2024-10-02 23:14:58

我设置了一个快速测试应用程序,但无法重现。

系列未缩放
series full Zoomed

这是我的系列初始化代码

chart1.Legends.Clear();
Random r = new Random();
for(int i = 0; i < 12; i++)
{
  Series series = new Series();
  series.ChartType = SeriesChartType.FastLine;
  for (int j = 0; j < 10000; j++)
  {
    series.Points.Add(r.NextDouble() + i + 3*Math.Sin((double)j/300.0f));
  }
  chart1.Series.Add(series);
  }

,这是图表初始化代码

chartArea1.AxisX.MajorGrid.Enabled = false;
chartArea1.AxisY.MajorGrid.Enabled = false;
chartArea1.CursorX.IsUserSelectionEnabled = true;
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(0, 0);
this.chart1.Name = "chart1";
this.chart1.Size = new System.Drawing.Size(616, 273);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";

异常数据是否依赖?您是否也为 X 提供值?您的系列使用的值是非常小还是非常大?例如,您是否尝试过将级数设置为简单的正弦波?

另外你用的是什么版本的控件和VS?您的目标框架是什么?

I setup a quick test app and cannot reproduce.

series unzoomed
series fully zoomed

Here is my series init code

chart1.Legends.Clear();
Random r = new Random();
for(int i = 0; i < 12; i++)
{
  Series series = new Series();
  series.ChartType = SeriesChartType.FastLine;
  for (int j = 0; j < 10000; j++)
  {
    series.Points.Add(r.NextDouble() + i + 3*Math.Sin((double)j/300.0f));
  }
  chart1.Series.Add(series);
  }

and here is the chart init code

chartArea1.AxisX.MajorGrid.Enabled = false;
chartArea1.AxisY.MajorGrid.Enabled = false;
chartArea1.CursorX.IsUserSelectionEnabled = true;
chartArea1.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea1);
this.chart1.Dock = System.Windows.Forms.DockStyle.Fill;
legend1.Name = "Legend1";
this.chart1.Legends.Add(legend1);
this.chart1.Location = new System.Drawing.Point(0, 0);
this.chart1.Name = "chart1";
this.chart1.Size = new System.Drawing.Size(616, 273);
this.chart1.TabIndex = 0;
this.chart1.Text = "chart1";

Is the exception data dependent? Are you providing values for X also? Do your series use values that are either very small or very large? Have you tried setting your series to a simple sin wave for example?

Also what versions of the controls and VS are you using? And what framework are you targetting?

守不住的情 2024-10-02 23:14:58

类似于 David T. Macknet 在上面的评论中所说的:

您可以添加一个处理程序来更好地管理缩放:

AddHandler aChart.AxisViewChanged, AddressOf Chart_ViewChanged

您的函数将如下所示:

Public Sub Chart_ViewChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataVisualization.Charting.ViewEventArgs)
        'The Zoom event changes the view state twice, first for the XAxis then the YAxis.'
End Sub

HTH

Similar to what David T. Macknet said above in a comment:

You can add a handler to manage the zooming a little better:

AddHandler aChart.AxisViewChanged, AddressOf Chart_ViewChanged

Your function will look something like this:

Public Sub Chart_ViewChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataVisualization.Charting.ViewEventArgs)
        'The Zoom event changes the view state twice, first for the XAxis then the YAxis.'
End Sub

HTH

物价感观 2024-10-02 23:14:58

我认为当 MSChart 计算“实际缩放”级别时会发生溢出异常。我在自定义缩放方面遇到了同样的问题。我通过将缩放包装到 try-catch 块中解决了这个问题。不过我没有尝试过,Dominique Jacquel 的解决方案似乎更可靠。

    try
    {
        Double GraphSize = Math::Abs(Graph->AxisX->Minimum-Graph->AxisX->Maximum) +                                             
                           Math::Abs(Graph->AxisY->Minimum-Graph->AxisY->Maximum);

        Double ScaleViewSize = Math::Abs(NewMinX-NewMaxX) + Math::Abs(NewMinY-NewMaxY);

        // if the difference of the two sizes are enormous, then Overflow exception occurs
        ActualZoom = Convert::ToInt32((GraphSize/ScaleViewSize)*100.0);

        // zoom
        Graph->AxisX->ScaleView->Zoom(NewMinX, NewMaxX);
        Graph->AxisY->ScaleView->Zoom(NewMinY, NewMaxY);
    }
    catch(OverflowException^){}

I think the Overflow Exception occures when the MSChart computes the 'Actual Zoom' level. I was facing the same issue with custom zooming. I fixed this issue by wrapping the zooming into a try-catch block. However I did'nt tried it, Dominique Jacquel's solution seems more solid.

    try
    {
        Double GraphSize = Math::Abs(Graph->AxisX->Minimum-Graph->AxisX->Maximum) +                                             
                           Math::Abs(Graph->AxisY->Minimum-Graph->AxisY->Maximum);

        Double ScaleViewSize = Math::Abs(NewMinX-NewMaxX) + Math::Abs(NewMinY-NewMaxY);

        // if the difference of the two sizes are enormous, then Overflow exception occurs
        ActualZoom = Convert::ToInt32((GraphSize/ScaleViewSize)*100.0);

        // zoom
        Graph->AxisX->ScaleView->Zoom(NewMinX, NewMaxX);
        Graph->AxisY->ScaleView->Zoom(NewMinY, NewMaxY);
    }
    catch(OverflowException^){}
眼藏柔 2024-10-02 23:14:58

我很确定这是因为 GDI+ 限制,即所谓的“绘图坐标的 GDI+ 硬边界”。不幸的是,我们不能用它做太多事情,因为这是 MSChart 控件实现中的一个问题,其中发生一些缩放,导致绘图值超出 GDI+ 绘图 API 的硬界限。解决方法是不使用缩放选项或 FastLine 绘图。

I am pretty sure that it is because of GDI+ limiation that is known as "GDI+ hard bounds of drawing coordinates". Unfortunetely we cannot do much with it because it is a problem in MSChart control implementation where some scaling occurs which causes the drawing values to go out of hard bounds for GDI+ drawing API. The workaround is to not use Zoom option or FastLine drawing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文