代码之家  ›  专栏  ›  技术社区  ›  MickeyfAgain_BeforeExitOfSO

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

  •  8
  • MickeyfAgain_BeforeExitOfSO  · 技术社区  · 15 年前

    This Question 已经在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 was caught   
      Message="Overflow error."   
      Source="System.Drawing"   
      StackTrace:   
         at System.Drawing.Graphics.CheckErrorStatus(Int32 status)   
    

    在这个问题上有任何帮助都会很好。干杯

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

    这里有人有线索或解决办法吗?

    5 回复  |  直到 15 年前
        1
  •  1
  •   zeFrenchy    14 年前

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

    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
    
        2
  •  0
  •   zeFrenchy    15 年前

    我设置了一个快速测试应用程序,无法复制。

    series unzoomed series fully 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";
    

    另外,您正在使用哪些版本的控件和VS?你的目标是什么?

        3
  •  0
  •   Chris Zeh    13 年前

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

    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
    

        4
  •  0
  •   Zoltan Tirinda    13 年前

    我认为当MSChart计算 实际变焦

        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^){}
    
        5
  •  0
  •   Community Mohan Dere    9 年前

    我敢肯定,这是因为GDI+补充剂被称为“ GDI+ hard bounds of drawing coordinates “。不幸的是,我们不能用它做很多事情,因为在MSChart控件实现中出现了一个问题,即某些缩放会导致绘图值超出GDI+绘图API的硬边界。解决方法是不使用缩放选项或快速线绘图。

    推荐文章