缩放后 MSChart 未处理的溢出异常
此问题一年多来, 在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我今天遇到了同样的问题,错误地将缩放设置为相同的开始值和结束值。
然后我尝试了以下实验:
您的数据点是否可能非常接近,以至于起点和终点之间的距离低于上面观察到的阈值?我建议您尝试将时间值乘以 100 或 1000,看看问题是否消失。
消除此问题的另一种方法是在 ScaleView 上设置 MinSize。
I encountered the same problem today when mistakenly setting the zoom with identical start and end values.
I then tried the following as an experiment:
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.
我设置了一个快速测试应用程序,但无法重现。
这是我的系列初始化代码
,这是图表初始化代码
异常数据是否依赖?您是否也为 X 提供值?您的系列使用的值是非常小还是非常大?例如,您是否尝试过将级数设置为简单的正弦波?
另外你用的是什么版本的控件和VS?您的目标框架是什么?
I setup a quick test app and cannot reproduce.
Here is my series init code
and here is the chart init code
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?
类似于 David T. Macknet 在上面的评论中所说的:
您可以添加一个处理程序来更好地管理缩放:
您的函数将如下所示:
HTH
Similar to what David T. Macknet said above in a comment:
You can add a handler to manage the zooming a little better:
Your function will look something like this:
HTH
我认为当 MSChart 计算“实际缩放”级别时会发生溢出异常。我在自定义缩放方面遇到了同样的问题。我通过将缩放包装到 try-catch 块中解决了这个问题。不过我没有尝试过,Dominique Jacquel 的解决方案似乎更可靠。
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.
我很确定这是因为 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.