Problems with real time chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
tenaris
Newbie
Newbie
Posts: 39
Joined: Fri Mar 02, 2007 12:00 am

Problems with real time chart

Post by tenaris » Mon Jan 18, 2010 5:29 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Problems with real time chart

Post by Narcís » Tue Jan 19, 2010 12:39 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

QTech
Newbie
Newbie
Posts: 16
Joined: Wed Jul 02, 2008 12:00 am

Re: Problems with real time chart

Post by QTech » Fri Mar 19, 2010 3:42 am

Hi tenaris,

Did you get your problem resolved?

tenaris
Newbie
Newbie
Posts: 39
Joined: Fri Mar 02, 2007 12:00 am

Re: Problems with real time chart

Post by tenaris » Mon Jun 07, 2010 5:03 pm

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
Attachments
DemoCurvas.zip
(203.15 KiB) Downloaded 917 times

QTech
Newbie
Newbie
Posts: 16
Joined: Wed Jul 02, 2008 12:00 am

Re: Problems with real time chart

Post by QTech » Mon Jun 07, 2010 9:19 pm

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

tenaris
Newbie
Newbie
Posts: 39
Joined: Fri Mar 02, 2007 12:00 am

Re: Problems with real time chart

Post by tenaris » Tue Jun 08, 2010 9:29 pm

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

QTech
Newbie
Newbie
Posts: 16
Joined: Wed Jul 02, 2008 12:00 am

Re: Problems with real time chart

Post by QTech » Tue Jun 08, 2010 9:50 pm

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problems with real time chart

Post by Yeray » Thu Jun 10, 2010 10:18 am

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?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Marcus
Newbie
Newbie
Posts: 4
Joined: Wed Feb 14, 2007 12:00 am

Re: Problems with real time chart

Post by Marcus » Tue Sep 04, 2012 10:34 am

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

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Problems with real time chart

Post by Sandra » Tue Sep 04, 2012 11:39 am

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Marcus
Newbie
Newbie
Posts: 4
Joined: Wed Feb 14, 2007 12:00 am

Re: Problems with real time chart

Post by Marcus » Tue Sep 04, 2012 2:08 pm

Dear Sandra,

thank your for the feedback. I'll check the links and come back to you if I have any further questions.

marcus

Marcus
Newbie
Newbie
Posts: 4
Joined: Wed Feb 14, 2007 12:00 am

Re: Problems with real time chart

Post by Marcus » Fri Sep 07, 2012 8:24 am

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

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Problems with real time chart

Post by Yeray » Mon Sep 10, 2012 9:50 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply