I encountered a complex error with the Dundas Charting for Winforms tool used with MS Visual Studio 2008 C #.
The following error occurs when a GUI event is raised on a Chart object when it is invalid. When an error occurs, the dundas chart shows a large X. ...
************** Exception Text ************** System.ArgumentOutOfRangeException: Axis Object - The Interval can not be zero Parameter name: diff at Dundas.Charting.WinControl.AxisScale.a(Double ) at Dundas.Charting.WinControl.Axis.a(Double , Double , AxisScaleSegment , DateTimeIntervalType& ) at Dundas.Charting.WinControl.Axis.a(ChartGraphics , Boolean , AxisScaleSegment , Boolean ) at Dundas.Charting.WinControl.Axis.b(ChartGraphics , Boolean , Boolean ) at Dundas.Charting.WinControl.Axis.Resize(ChartGraphics chartGraph, ElementPosition chartAreaPosition, RectangleF plotArea, Single axesNumber, Boolean autoPlotPosition) at Dundas.Charting.WinControl.ChartArea.a(ChartGraphics ) at Dundas.Charting.WinControl.ChartPicture.Resize(ChartGraphics chartGraph, Boolean calcAreaPositionOnly) at Dundas.Charting.WinControl.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly, RenderingType renderingType, XmlTextWriter svgTextWriter, Stream flashStream, String documentTitle, Boolean resizable, Boolean preserveAspectRatio) at Dundas.Charting.WinControl.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly) at Dundas.Charting.WinControl.Chart.OnPaint(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The scenario is as follows:
- I have a grid that has a list of objects that reference a constructed row.
- The plot is updated every 1 second using a chart. Invoke (AddData)
This is the event that causes the failure:
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { AppDataSeries boundData = dataGridView1[e.ColumnIndex, e.RowIndex].OwningRow.DataBoundItem as AppDataSeries; if (boundData.Tag != null)
The figure is as follows
Background thread captures
Raises an event
OnDataAvailable every second
Holds the handler
void serviceWrapperInstance_DataAvailable(object sender, DataAvailableEventArgs e) { if (e.ViewId == currentViewId) { if (MUChart.InvokeRequired) { MUChart.Invoke((MethodInvoker)AddData); } else { AddData(); } } } public void AddData() { if (MUChart.Series.Count > 0) { for (int i = 0; i < currentViewSeries.Count; i++) { AddNewPoint(currentViewSeries[i].XValue, MUChart.Series[i], currentViewSeries[i].YValue * ((currentViewSeries[i].IsInverse) ? -1 : 1), currentViewSeries[i].ChartColor); dataSaver[MUChart.Series[i].Name].Add(new DataPoint(currentViewSeries[i].XValue, (double)currentViewSeries[i].YValue)); } } } public void AddNewPoint(double xValue, Series ptSeries, double yValue, Color pointColor) { try { ptSeries.Points.AddXY(xValue, yValue); if (draggedDroppedSeriesMapper.ContainsKey(ptSeries)) foreach (Series item in draggedDroppedSeriesMapper[ptSeries].DraggedDroppedSeriesVersions) item.Points.AddXY(xValue, yValue); MUChart.Invalidate();
The interesting thing about this error is that it does not happen on all machines. I noticed that this is happening on high-end machines, such as the 8-core DELL processor, and the new quad-core laptop that we got here. This raised a suspicion of a thread problem; however, the threads seem to be in order, since the chart object is accessing from the same main thread.
Please help me with this.
UPDATE is a setter assignment that takes place in the dataGridView1_CellEndEdit function MUChart.Series [boundData.SeriesName] .ChartArea = boundData.ChartArea.ToString (); calls chart.invalidate internally, while the called AddData function, which updates this chart, calls it explicitly. I read in the MSDN library that "control.invalidate" does not cause synchronous paint if control.update is called after it. I am pretty sure that the conflict occurs in the event of invalidity, although everything happens in the same thread, since the redrawing occurs asynchronously. I realized that this is happening, but I do not know how to avoid it. control.update does nothing good to me.
ChangeTheChartConfigurations (); DrawTheChanges () ---- โ โ it works asynchronously UpdateDataPoints () DrawTheChanges () ---- โ> it works while the first change has not yet occurred. For example, a series could be moved to the area of โโdifference diagrams, and Dundas.Charting.WinControl.AxisScale.a (Double) (the last function in the stack trace) is called in the already hidden region of the diagram. that just a thought
UPDATE
I registered the thread ID from both the event handler and the AddNewPoint function, and it was the same as
main stream