Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3590
What is the most efficient way to update a series multiple times a second with many points?
posted

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. 

Parents
No Data
Reply
  • 30692
    Suggested Answer
    Offline posted

    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

Children