Tuesday, May 17, 2011

How To Use a Stripchart

Written by Erez Wenger - May 2011

In this post we show how to easily add a stripchart to your user interface and how to write code that will present data on it.


Although graph and stripchart controls are both graphic represention of data, they are very different :
  • graph control is usually used for static data where you can plot arrays of points, lines and polygonal shapes using  a single command .
  • stripchart control is used for dynamic data where you plot a single point for a given time (although you can plot multiple points).
The best examples for stripchart are electronic scope or E.K.G. - the value on the screen changes at real-time according to the measured voltage, you can also see a trace of previously measured values for convenience.

The most common and simple way of plotting on a stripchart is by using a timer, on the timer's control callback you plot a new value for every timer's tick.

The command for plotting a new value on the stripchart is PlotStripChartPoint.

The next example shows how to plot a sine wave on the stripchart:

case EVENT_TIMER_TICK: //on the timer callback

y=sin(t*Pi()); //calculating the new value according to the time counter variable
PlotStripChartPoint (panelHandle, PANEL_STRIPCHART, y); //plotting the new value
t+=0.05; //increasing the time counter variable
break;



In order to show the values on the stripchart in a reasonable way there are some stripchart features that usually needs to be updated, here are some of them (look at some of the others on your own):
  • go to the UIR and edit the stripchart control.

  • Change the number of Points per Screen to a desired value - the more points you have the longer the trace is.
  • Go to Left Y-axis and choose your Minimum and Maximum (in the sine wave they are 1,-1).



You might also want to check our post on multi-trace stripcharts.

2 comments:

  1. where should i enter the line "case EVENT_TIMER_TICK"?

    ReplyDelete
    Replies
    1. This case sits within the timer function - the one which is associated with the GUI timer

      Delete