This page describes the functions and methods supported by the XYPlot
class for sending data, setting properties and controlling the X-Y Plot visualizer from your Arduino sketch. The xy-plot visualizer shows numerical data on a graph with separate values for the x (horizontal) and y (vertical) axes.
Data is grouped in series for plotting. Series are identified using a series name and new values are appended to the series and shown on the plot as they arrive. You can assign different marker symbols, lines and colors to each series. A series may be connected to the left or right y-axis.
By default, all data sent for plotting is shown in the visualizer. You can create multiple plots and control which data is shown on each using message channels. To use channels, supply a channel name in the XYPlot
constructor.
Example
This example sends the voltage from the first two analog channels as x and y values to MegunoLink every 200 ms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include "MegunoLink.h" // Helpful functions for communicating with MegunoLink. // Millis value when the data was last sent. long LastSent; // Interval (milliseconds) between sending analog data const unsigned SendInterval = 200; // [ms] // The plot we are sending data to. XYPlot MyPlot; void setup() { Serial.begin(9600); LastSent = millis(); MyPlot.SetTitle("My Analog Measurement"); MyPlot.SetXlabel("Channel 0"); MyPlot.SetYlabel("Channel 1"); MyPlot.SetSeriesProperties("ADCValue", Plot::Magenta, Plot::Solid, 2, Plot::Square); } void loop() { if ((millis() - LastSent) > SendInterval) { LastSent = millis(); int XDataValue = analogRead(0); int YDataValue = analogRead(1); MyPlot.SendData("ADCValue", XDataValue, YDataValue); } } |
Methods
These methods are specific to XY plots.
Constructor:
- XYPlot(ChannelName — optional, Destination — optional )
Send single measurement:
- SendData(SeriesName, XValue, YValue, SeriesProperties — optional )
- SendData(SeriesName, XValue, YValue, Color, LineStyle, LineWidth, MarkerStyle)
- SendData(SeriesName, XValue, YValue, RGBColor, LineStyle, LineWidth, MarkerStyle)
- SendData(SeriesName, XValue, YValue, NumberOfDecimalPlaces, SeriesProperties — optional )
- SendData(SeriesName, XValue, YValue, NumberOfDecimalPlaces, Color, LineStyle, LineWidth, MarkerStyle)
Send multiple measurements:
- SendData(SeriesName, XValues, YValues, NumberOfValues, SeriesProperties — optional )
- SendData(SeriesName, XValues, YValues, NumberOfValues, NumberOfDecimalPlaces, SeriesProperties — optional )
The following methods, common to all plot visualizers, can be used to control the plot’s appearance:
- SetTitle(Title)
- SetXLabel(Label)
- SetYLabel(Label)
- SetY2Label(Label)
- SetSeriesProperties(SeriesName, Color, LineStyle, LineWidth, MarkerStyle, AxisOption)
- SetSeriesProperties(SeriesName, SeriesProperties)
- Clear()
- Clear(SeriesName)
- SetYRange(LowerLimit, UpperLimit)
- SetY2Range(LowerLimit, UpperLimit)
- SetYVisible(Visible — optional)
- SetY2Visible(Visible — optional)
Detailed Descriptions
The parameters and functions for the XYPlot
class are described in detail below. Optional parameters are surrounded by []
s. Text parameters support memory string and flash strings (where available).
XY Plot Constructor
Constructs an x-y plot variable, which can be used to send data, format and control XY Plot visualizers.
XYPlot([ChannelName], [Destination])
Name | Type | Required? | Description |
---|---|---|---|
ChannelName |
const char*, const __FlashStringHelper* |
No | sets the channel used for all methods called on the variable. If missing, data is sent to the default channel |
Destination |
Print& |
No | the stream used for all methods called on the variable. If missing, data is sent to the standard Serial port |
1 2 3 4 5 6 |
#include "MegunoLink.h" XYPlot MyPlot; XYPlot MyPowerPlot("Power"); XYPlot MyTemperaturePlot(F("Temperture")); XYPlot MyDebugPlot("Range", Serial1); |
Sending Data
XYPlot
has a variety of methods to send data to MegunoLink. They all require a series name, an x-value and a y-value. You can also include styling information (such as the marker symbol or line color) and the number of decimal places (for float
or double
values). Finally, you can send an array of x- and y-values in one go. Sending styling information overrides the style in MegunoLink.
The available methods for sending a single data-point are:
SendData(SeriesName, XValue, YValue, [SeriesProperties])
SendData(SeriesName, XValue, YValue, Color, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendData(SeriesName, XValue, YValue, RGBColor, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendData(SeriesName, XValue, YValue, NumberOfDecimalPlaces, [SeriesProperties])
SendData(SeriesName, XValue, YValue, NumberOfDecimalPlaces, Color, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
SendData(SeriesName, XValue, YValue, NumberOfDecimalPlaces, RGBColor, [LineStyle], [LineWidth], [MarkerStyle], [AxisOption])
The available methods for sending an array of data-points are:
SendData(SeriesName, XValues, YValues, NumberOfValues, [SeriesProperties])
SendData(SeriesName, XValues, YValues, NumberOfValues, NumberOfDecimalPlaces, [SeriesProperties])
Name | Type | Required? | Description |
---|---|---|---|
SeriesName |
Text |
Yes | The name of the series the data belongs to. A series is a collection of points, optionally connected by a line. |
XValue |
Number |
Yes | The x-value to add to the plot for SeriesName |
YValue |
Number |
Yes | The y-value to add to the plot for SeriesName |
XValues |
Array of numbers |
Yes | An array of NumberOfValues x-values to add to the plot for SeriesName |
YValues |
Array of numbers |
Yes | An array of NumberOfValues y-values to add to the plot for SeriesName |
NumberOfValues |
Number | Yes | The number of values in the XValues and YValues arrays. |
SeriesProperties |
Text |
No | A series property string to set the series style |
Color |
Plot::Colors |
Yes | One of the supported color constants to set the series line and marker color |
RGBColor |
32 bit number | Yes | A 24 bit RGB color. In hex the components are: 0xRRGGBB where RR , GG and BB are 8 bit values for the red, green and blue components of the color. |
LineStyle |
Plot::LineStyle |
No | One of the supported line-style constants to set the series line style. Defaults to Plot::Solid |
LineWidth |
Number | No | The thickness to draw the series line. Defaults to 1 |
MarkerStyle |
Plot::MarkerStyle |
No | One of the supported marker-style constants to set the series marker style. Defaults to Plot::Circle |
AxisOption |
Plot::AxisOption |
No | One of the supported axis option constants to set which axis the series is linked to. Defaults to Plot::DefaultAxis , which doesn’t change the axis the series is linked to |
DecimalPlaces |
Number | Yes | The precision to use when sending floating-point numbers. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
MyPlot.SendData("Voltage", 5, 12, TimePlot::Red, TimePlot::Dashed, 3, TimePlot::Circle); float Analog0 = analogRead(0); float Analog1 = analogRead(1); MyPlot.SendData("Temperature", Analog0, Analog1); MyPlot.SendData("Temperature", Analog0, Analog1, "r:s4"); MyPlot.SendData("Temperature", Analog0, Analog1, TimePlot::Red, TimePlot::Dashed, 3, TimePlot::Circle); // Send an array of measurements int NumberOfMeasurements = 10; float TimeStamps[NumberOfMeasurements]; float Measurements[NumberOfMeasurements]; for(int i = 0; i < NumberOfMeasurements; ++i) { TimeStamps[i] = millis(); Measurements[i] = analogRead(0); delay(10); } MyPlot.SendData("Analog Measurements", TimeStamps, Measurements, NumberOfMeasurements); |