Using the latest version (11.1) of the datachart I need to add roughly ~300 points 10 times a second so that the chart looks like it is flowing smoothly. Currently I have a observable collection that I simply add values to in a for loop every 1/10th second. What I want to make sure of is that the chart does not try to redraw in between each add or even group of adds. I would want it to redraw only after all 300 points are added. Is there I way I can tell how often the graph is redrawing itself? Also, is there a better way of minimizing redraws? Should I disconnect the observable collection, add the values and then reconnect it?
Any optimization advice would be appreciated.
Mike,
The chart will defer most of the work it has to do until you relinquish the UI thread. So, for example, when you add the points in a handler from a DispatcherTimer when that handler finishes executing, the UI thread is free again, and the chart reconciles your data changes with its internal model and schedules a rerender.
That being said, some tracking work it being done as you make each data change, so there may be some differences based on how you add the points to the collection. But the chart wont attempt to rerender until you yield up the UI thread.
This is not how the chart behaved in earlier versions, so if you were seeing a marked difference between various updating mechanisms in earlier versions, then thats why.
I wouldn't necessarily recommend doing anything like detaching the observable collection and reattaching. The work done during the attach can be much more overhead than modifications of the attached collection.
One thing to consider is that unless you plan on updating properties on an item bound to the chart, you may want to consider NOT implementing INotifyPropertyChanged. You don't need this interface if you are only ever adding and removing points to the series, rather than updating the values of existing points. And there is some overhead involved in the chart adding and removing all the event handlers it needs to deal with INotifyPropertyChanged. So, if you don't need it, I would recommend leaving it out.
I believe we have a recent blog post with some other recommendations for chart performance. I'll try to find it for you.
-Graham
This blog post from Kiril captures some of the other performance recommendations I would recommend. http://blogs.infragistics.com/blogs/kiril_matev/archive/2011/04/07/tuning-the-xamdatachart-for-blazing-fast-charting.aspx
Please note about the Label DataTemplates item. In 11.1 and later the recommendation is reversed. You are better of NOT using DataTemplates in the axis labels unless you need to. There were some inefficiencies in the non templated case prior to 11.1
Furthermore, if you don't need an axis's labels, its more efficient if you collapse the label panel. The resolution property can also help quite a bit in certain scenarios, just be aware that the greater you raise the value, the less faithfully the line will represent the underlying data, but more and more efficient to render geometry will be produced.