Problems with real time chart
Problems with real time chart
I'm building a demo for a real time charting application.
I got a good/regular performance populating series in a worker thread (tChart.Series.Add & tChart.Series.RefreshSeries) and refreshing (tChart1.Refresh) in the main GUI thread (form).
The data is read from a csv file, 30 series with 5300 points per serie.
Suddenly I get an exception:
************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Steema.TeeChart.Styles.FastLine.CalcPosition(Int32 index, Int32& x, Int32& y)
at Steema.TeeChart.Styles.FastLine.DrawValue(Int32 index)
at Steema.TeeChart.Styles.FastLine.Draw()
at Steema.TeeChart.Styles.Series.DrawSeries()
at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools)
at Steema.TeeChart.Chart.InternalDraw(Graphics g)
at Steema.TeeChart.TChart.Draw(Graphics g)
at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)
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.OnMessage(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 code in thread appears to be ok, sometimes the app throws the exception but not the most of times.
The teechart version is TeeChart Pro v2 for Visual Studio .NET
Thanks
I got a good/regular performance populating series in a worker thread (tChart.Series.Add & tChart.Series.RefreshSeries) and refreshing (tChart1.Refresh) in the main GUI thread (form).
The data is read from a csv file, 30 series with 5300 points per serie.
Suddenly I get an exception:
************** Exception Text **************
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Steema.TeeChart.Styles.FastLine.CalcPosition(Int32 index, Int32& x, Int32& y)
at Steema.TeeChart.Styles.FastLine.DrawValue(Int32 index)
at Steema.TeeChart.Styles.FastLine.Draw()
at Steema.TeeChart.Styles.Series.DrawSeries()
at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools)
at Steema.TeeChart.Chart.InternalDraw(Graphics g)
at Steema.TeeChart.TChart.Draw(Graphics g)
at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)
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.OnMessage(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 code in thread appears to be ok, sometimes the app throws the exception but not the most of times.
The teechart version is TeeChart Pro v2 for Visual Studio .NET
Thanks
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Problems with real time chart
Hello tenaris,
Could you please attach a simple example project we can run "as-is" to reproduce the problem here and let us know the exact TeeChart v2 build you are using?
Thanks in advance.
Could you please attach a simple example project we can run "as-is" to reproduce the problem here and let us know the exact TeeChart v2 build you are using?
Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Problems with real time chart
Hi tenaris,
Did you get your problem resolved?
Did you get your problem resolved?
Re: Problems with real time chart
We haven't solved the problem with TeeChart and FastLine series.
Attached is a running demo with 9 series with more than 3000 points. Let it run and after a while the exception will be thrown.
This is an old problem we need to solve. I hope you can help us.
thanks
Attached is a running demo with 9 series with more than 3000 points. Let it run and after a while the exception will be thrown.
This is an old problem we need to solve. I hope you can help us.
thanks
- Attachments
-
- DemoCurvas.zip
- (203.15 KiB) Downloaded 922 times
Re: Problems with real time chart
Hi tenaris
The TeeChart I'm using is for Delphi 2007. I was having access violations after running my application with the the chart being updated in real time for a view hours. I've got 8 line series each being updated by its own thread. I fixed it by turning off the auto repaint on the chart while I was updating my line series with data. The following code is in Delphi but I think it would be easy to re-write in C#:
Good luck.
QTech
The TeeChart I'm using is for Delphi 2007. I was having access violations after running my application with the the chart being updated in real time for a view hours. I've got 8 line series each being updated by its own thread. I fixed it by turning off the auto repaint on the chart while I was updating my line series with data. The following code is in Delphi but I think it would be easy to re-write in C#:
Code: Select all
{ turn off chart auto repaint just in case it is on }
if LineSeries.ParentChart.AutoRepaint = True then
LineSeries.ParentChart.AutoRepaint := False;
QTech
Re: Problems with real time chart
The AutoRepaintProperty was originally set to false, so the property is always off.
I have just one thread to populate all series and the Method RefreshSeries is called every time new points are added to a serie. The tChart1.Refresh (where the exception is thrown) is called on a Tick timer from main form.
In thread, a few lines after calling RefreshSeriesMethod I clear the series and asynchronously the tChart1.Refresh repaints the Chart. I think the problem is here for any reason.
I hope you can check the source code, maybe it's not well implemented.
Thanks
I have just one thread to populate all series and the Method RefreshSeries is called every time new points are added to a serie. The tChart1.Refresh (where the exception is thrown) is called on a Tick timer from main form.
In thread, a few lines after calling RefreshSeriesMethod I clear the series and asynchronously the tChart1.Refresh repaints the Chart. I think the problem is here for any reason.
I hope you can check the source code, maybe it's not well implemented.
Thanks
Re: Problems with real time chart
Hi tenaris
I don't have TeeChart for .NET so I couldn't run your code but I had a brief look at your source code. It looks like a bug in the TeeChart component itself.
Sorry, can't help you any further than this.
QTech
I don't have TeeChart for .NET so I couldn't run your code but I had a brief look at your source code. It looks like a bug in the TeeChart component itself.
Sorry, can't help you any further than this.
QTech
Re: Problems with real time chart
Hi tenaris,
TeeChart is not thread-safe so you should control it. I think that the problem could be here. Although I'm not an expert about multitasking I can see you are working with "rigid delays" (System.Threading.Thread.Sleep(300)) and I'm not sure if it could open the possibility to try to redraw the chart at the same time you add a point.
Have you tried with semaphores or make a thread wait for another to finish more than a hardcoded time?
TeeChart is not thread-safe so you should control it. I think that the problem could be here. Although I'm not an expert about multitasking I can see you are working with "rigid delays" (System.Threading.Thread.Sleep(300)) and I'm not sure if it could open the possibility to try to redraw the chart at the same time you add a point.
Have you tried with semaphores or make a thread wait for another to finish more than a hardcoded time?
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Problems with real time chart
Dear TeeChart-Team,
I recently ran into the same problem tenaris had 2 years ago.
Is there by now a recommanded way to handle this issue?
Is the latest release of TeeChart thread-safe?
I appreciate highly any advice or hint.
Regards
Marcus
I recently ran into the same problem tenaris had 2 years ago.
Is there by now a recommanded way to handle this issue?
Is the latest release of TeeChart thread-safe?
I appreciate highly any advice or hint.
Regards
Marcus
Re: Problems with real time chart
Hello Marcus,
TeeChart isn't thread-safe and you should control it. For this reason, I recomend you taking a look in next threads, that can help you to avoid problems:
http://www.teechart.net/support/viewtop ... ing#p10982
http://www.teechart.net/support/viewtop ... 99&start=0
http://www.teechart.net/support/viewtop ... =threading
http://www.teechart.net/support/viewtop ... ing#p47454
Thanks,
TeeChart isn't thread-safe and you should control it. For this reason, I recomend you taking a look in next threads, that can help you to avoid problems:
http://www.teechart.net/support/viewtop ... ing#p10982
http://www.teechart.net/support/viewtop ... 99&start=0
http://www.teechart.net/support/viewtop ... =threading
http://www.teechart.net/support/viewtop ... ing#p47454
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Problems with real time chart
Dear Sandra,
thank your for the feedback. I'll check the links and come back to you if I have any further questions.
marcus
thank your for the feedback. I'll check the links and come back to you if I have any further questions.
marcus
Re: Problems with real time chart
Dear Sandra,
if I got everything right, the main problem is that the data of one or all series is changing while the chart is beeing drawn.
Thus one should take over control of the (re)painting of the chart and
1) starting the repaint only if all data of the series has been changed
2) changing data of series only if painting of chart has finished
The first point can be implemented straight forward with setting autorepaint of the chart-Control to false and calling the chart.refresh method after changing data.
The second bears some problems in my implemention:
I created some customs series classes by inheriting from the teecharts default series classes (like e.g. TeeChart.Styles.line).
Theses customs series classes gets some data objects and after a change of the data objects starts to update itself.
The customs series look roughly like that:
Unfortunatly I couldn't find any property of the Series.Chart Object indicating wether is chart is currently drawn or not. And since the BeforeDraw and AfterDraw events are only raised in the TChart class and not the Chart class I could not create my own property. Thus I have no idea how to prevent the update /change of the series data at (1) if the chart is drawing itself. Or could the BeforeDrawValues and AfterDrawValues events of the series used for this purpose?
At (2) I wanted to call the TChart.Refresh methode but again it is not accessable via the Chart-Object. Could the Chart.Invalidate methode be used?
BTW: I'm using TeeChart.NET v2
marcus
if I got everything right, the main problem is that the data of one or all series is changing while the chart is beeing drawn.
Thus one should take over control of the (re)painting of the chart and
1) starting the repaint only if all data of the series has been changed
2) changing data of series only if painting of chart has finished
The first point can be implemented straight forward with setting autorepaint of the chart-Control to false and calling the chart.refresh method after changing data.
The second bears some problems in my implemention:
I created some customs series classes by inheriting from the teecharts default series classes (like e.g. TeeChart.Styles.line).
Theses customs series classes gets some data objects and after a change of the data objects starts to update itself.
The customs series look roughly like that:
Code: Select all
Class MySeries
inherits TeeChart.Styles.line
Public WithEvents DataList as DataListClass
Sub DataChanged() handles DataList.changed
'' (1) here should be checked if chart is beeing drawn
BeginUpdate()
Clear()
For Each d as DataClass in DataList
add(d.x,d.y)
Next d
EndUpdate()
'' (2) here should the chart force to update itself
End Sub
End Class
At (2) I wanted to call the TChart.Refresh methode but again it is not accessable via the Chart-Object. Could the Chart.Invalidate methode be used?
BTW: I'm using TeeChart.NET v2
marcus
Re: Problems with real time chart
Hi,
I'd try adding a flag to control if the chart has been ended being drawn. You could set the flag to false at BeforeDraw event and to true at AfterDraw. And then, you could add a condition / wait at the beginning of your DataChanged function.
If you still have problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here.
It would be also helpful if you could give it a try to the actual TeeChart version, to see if the behaviour changes with it.
I'd try adding a flag to control if the chart has been ended being drawn. You could set the flag to false at BeforeDraw event and to true at AfterDraw. And then, you could add a condition / wait at the beginning of your DataChanged function.
If you still have problems with it, please try to arrange a simple example project we can run as-is to reproduce the problem here.
It would be also helpful if you could give it a try to the actual TeeChart version, to see if the behaviour changes with it.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |