Page 1 of 1
Problems with real time chart
Posted: Mon Jan 18, 2010 5:29 pm
by 9644416
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
Re: Problems with real time chart
Posted: Tue Jan 19, 2010 12:39 pm
by narcis
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.
Re: Problems with real time chart
Posted: Fri Mar 19, 2010 3:42 am
by 12049531
Hi tenaris,
Did you get your problem resolved?
Re: Problems with real time chart
Posted: Mon Jun 07, 2010 5:03 pm
by 9644416
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
Re: Problems with real time chart
Posted: Mon Jun 07, 2010 9:19 pm
by 12049531
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#:
Code: Select all
{ turn off chart auto repaint just in case it is on }
if LineSeries.ParentChart.AutoRepaint = True then
LineSeries.ParentChart.AutoRepaint := False;
Good luck.
QTech
Re: Problems with real time chart
Posted: Tue Jun 08, 2010 9:29 pm
by 9644416
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
Re: Problems with real time chart
Posted: Tue Jun 08, 2010 9:50 pm
by 12049531
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
Re: Problems with real time chart
Posted: Thu Jun 10, 2010 10:18 am
by yeray
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?
Re: Problems with real time chart
Posted: Tue Sep 04, 2012 10:34 am
by 9644269
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
Re: Problems with real time chart
Posted: Tue Sep 04, 2012 11:39 am
by 10050769
Re: Problems with real time chart
Posted: Tue Sep 04, 2012 2:08 pm
by 9644269
Dear Sandra,
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
Posted: Fri Sep 07, 2012 8:24 am
by 9644269
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:
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
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
Re: Problems with real time chart
Posted: Mon Sep 10, 2012 9:50 am
by yeray
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.