Hi Chuck,
For realtime charts, we suggest to create it in two part.
(a) Data acquisition: This part acquires the data and put them in data arrays (in memory). It does not draw the chart. The data acquisition can be run on a timer in the GUI thread (such as running once every 5ms), or it can be run as an interrupt handler or in a loop in another thread, etc.
(b) Chart plotting: This part draws the chart periodically. The period can be different from the data acquisition. For example, the data acquisition can run every 5ms, which the chart can be plotted every 100ms. The charting part can be triggered by a timer. Everytime the timer event occurs, if checks the data arrays to see if there is new data, and plot them if the data has changed.
In addition to updating the chart periodically, there is also a rate limiting feature in ChartDirector. With this method, you can update the chart as fast as you like. When ChartDirector detects that the updates are occuring too frequently, it will try to group several updates into one update. See:
http://www.advsofteng.com/doc/cdnet.htm#WinChartViewer.UpdateInterval.htm
With the above code structure, the data acquisition can be designed to not being affected by the charting, as the data acquisition can run on another thread or interrupt handler. The data acquisition code should also be very fast as it only reads data and store them in memory, without doing anything else.
In other words, if multi-threading is needed, it is better to put the data acquisition in a separate thread, and not the charting code. It is better to put the charting code in the GUI thread, as the chart is mainly a GUI feature, while the data acquisition a "background feature" (similar to an interrupt handler).
In the examples that come with ChartDirector, the two parts above are triggered by two separate timers, not necessarily running at the same frequency. So the data acquisition can occur at a higher frequency than the chart plotting.
ChartDirector charts usually can be plotted quite fast and the speed normally is not too sensitive to the number of data points. It means plotting 100 points and 10000 points take similar amount of time. The speed is more related to the number of pixels on the chart. If there are a huge number of points (much higher than the pixel width of the chart so the points), there is also a "fast line mode" to allow line charts to be plotted very fast.
One thing to note is that in addition to plotting the chart, ChartDirector also allows user interactions, like pop-up tooltips, track cursors, etc.. The pop-up tooltips in particular can take more time to compute than plotting the chart itself. So if the chart is updated very fast, you may want not to use pop-up tooltips. The track cursor can also display data points when the mouse is moving over the chart and is faster.
Regards
Peter Kwan |