Navigation: Standard Controls > Analog Plot > Drawings >

Drawing Live Data

 

 

 

 

Drawing live data involves used incoming data information to draw information on the plot based on the data and/or the time of the data arrival. Incoming data can be accessed using values such as:

[plotControlName.ch0]                              // current value plotted
[plotControlName.lastValueCh0]          // last value plotted

[plotControlName.timeCh0]                    // current time plotted

[plotControlName.lastTimeCh0]                    // last time plotted

[plotControlName.avgCh0]                    // Cumulative since reset of the average value plotted

[plotControlName.minCh0]                    // Cumulative since reset of the minimum value plotted

[plotControlName.maxCh0]                    // Cumulative since reset of the maximum value plotted

 

Note that some of these values could be used for a plot channels formula, such as to plot the maximum or average value of a channel. The min/max/average value can be cleared with the pop-up menu or !plotControlName.resetMinMaxAvg.

 

Using these value, drawings can based their X or Y coordinates on the data returned.

For example, drawing a red circle if a value exceeds a threshold at certain level by placing code it in plot's Event Code:
 

<analog>!if [this.ch0] > 100 !then !this.drawCircle [this.timeCh0], [this.ch0], 1a, RED
(this is used to reference the control executing the code)


 

For the next example, the maximum number of drawing was increased to 5000 (!plot.maxDrawings=5000) and the plot channel's colors in Settings were set using using HSL color transparency of 70, and channel "show" turned off.  Code is placed in the Analog Plot's Event Code.

 

// plot each channel as a bar from Y of 0 using data times for X values

<analog>!plot.drawFilledRect [plot.lastTimeCh0], 0, [plot.timeCh0], [plot.ch0], [plot.colorCh0]

<analog>!plot.drawFilledRect [plot.lastTimeCh0], 0, [plot.timeCh0], [plot.ch1], [plot.colorCh1]

<analog>!plot.drawFilledRect [plot.lastTimeCh0], 0, [plot.timeCh0], [plot.ch2], [plot.colorCh2]

<analog>!plot.drawFilledRect [plot.lastTimeCh0], 0, [plot.timeCh0], [plot.ch3], [plot.colorCh3]

 

 

 

A more complex example follows where the values of 4 channels are stacked on top of each other as filled rectangles and using data times for X1 and X2. Variables are created and used to hold the cumulative values of the 4 channels for defining the Y2 coordinates.

 

<load>!makeVar varCh0_1

<load>!makeVar varCh0_1_2

<load>!makeVar varCh0_1_2_3
<load>!plot.maxDrawings=5000

 

// calculate cumulative values to stack rectangles

<analog>!varCh0_1={ [plot.ch0] + [plot.ch1] }

<analog>!varCh0_1_2={ [plot.ch0] + [plot.ch1] + [plot.ch2] }

<analog>!varCh0_1_2_3={ [plot.ch0] + [plot.ch1] + [plot.ch2] + [plot.ch3] }

 

// plot channel 0 as rectangle from last time to current time

<analog>!plot.drawFilledRect [plot.lastTimeCh0], 0, [plot.timeCh0],[plot.ch0],[plot.colorCh0]

 

// plot channel 1 on top of channel 0

<analog>!plot.drawFilledRect [plot.lastTimeCh0], [plot.ch0], [plot.timeCh0], [varCh0_1], [plot.colorCh1]

 

// plot channel 2 on top of channel 1

<analog>!plot.drawFilledRect [plot.lastTimeCh0], [varCh0_1], [plot.timeCh0], [varCh0_1_2], [plot.colorCh2]

 

// plot channel 3 on top of channel 2

<analog>!plot.drawFilledRect [plot.lastTimeCh0], [varCh0_1_2], [plot.timeCh0], [varCh0_1_2_3], [plot.colorCh3]

 

To execute the <load> instructions, enter !runLoad in the Debug/CLI if not saved and loaded.

 

The plot and code was configured as follows:

- All normal plot channels were turned off ('Show' unchecked in the plot settings)

- The sin_cos_digital code was modified to send only positive (abs()) values

- The delay was increased in the controller code

 

 

Information or status events can be sent to be plotted as drawing, such as automatically annotating on the plot when the system status changes:

Serial.println("!plot.drawText [plot.timeCh0], 80, Pump On, 10, BLUE");

 

 

Between available drawing instructions and accessing plotting values, the possibilities for unique visualization of data is nearly unlimited. Math operations may be accessed or operated on the plotted data such as mean value, standard deviation  values and other uses.

 

 

 

 

 

Copyright © 2024 SelmaWare Solutions, LLC