views:

362

answers:

1

I've been trying to figure out what is the appropriate way to render real-time data as a line graph in WPF. And by real-time I actually mean, data that is being collected from a USB device that generates data at a rate of approximately 40Hz. There are multiple (up to 7) streams of data that I'm reading at 40Hz in an asynchronous fashion.

I've tried using two off-the shelf solutions (WPF Toolkit charting and Swordfish charts) and almost looked into the Dynamic Data Visualization component but gave up on it after reading some comments on their forum. It seems that off-the-shelf charting solutions are geared towards static charts and I actually need something similar to the Windows Task Manager - only much faster and with way more data points.

Currently, I've rolled my own solution which seems to work the best so far but I have a feeling that I'm missing something because it seems that I should be able to get better performance out of it.

The requirements are that it should be able to handle a constant range of about 10000 points in a sliding window - as new data comes in (at 40Hz), old data get's pushed to the left outside of the visible range. And it needs to sustain this rate for at least 20 - 30 minutes (a total of about 75 - 100 thousand points per data stream).

My current custom implementation is a based on a component that inherits from Shape and uses a StreamingGeometry for the DefinigGeometry. The data coming in from the device is passed to the component via a queue to improve performance due to the inherent "bursting effect" and after a dequeue operation, the component is invalidated.

So, my question is, am I on the right path or am I completely wrong? What is the most efficient way to accomplish such data visualization in WPF? Any help or hints would be greatly appreciated.

+1  A: 

The retained mode rendering of WPF makes drawing/redrawing custom charts and images tricky to make performant, especially when those drawings contain a lot of objects.

The fastest drawing I've been able to do in WPF is by using a WritableBitmap and filling it with a call to WritePixels, which may be an option for you. It vastly exceeded the drawing speed of the chart I wrote using PathGeometries and drawing to a Canvas.

I'm interested to see if there is a quicker middle ground.

Ed Gonzalez
One possible 'middle ground' would be to draw it onto a RenderContext in an OnRender override. If nothing else this gives an enormous sense of mental relief as it feels much more like trad GDI/WinForms painting... (More seriously, it should give access to decent rendering primitives without the overhead of building the retained-mode tree that is so often merely a redundant repetition of ones own object-graph)
Will Dean