The ui_chart node supports several data formats to populate different chart types. Depending on the chart type, you should structure your msg.payload as follows:
1. Array of Objects (Labels and Series)
Used for Bar, Pie, and other categorical charts. You can pass an object containing labels, series, and data arrays, or an array of objects where each object represents a data point.
Option A: Single Object with Arrays
var m = {
"series": ["X", "Y", "Z"],
"data": [[5, 6, 9], [3, 8, 5], [6, 7, 2]],
"labels": ["Jan", "Feb", "Mar"]
};
msg.payload = [m]; // Note: payload is often an array containing the object
Option B: Array of Data Point Objects
Each object in the array can define its own label, payload, and series.
var m = [
{label: "A", payload: 22, series: "X"},
{label: "B", payload: 66, series: "X"},
{label: "C", payload: 42, series: "X"},
{label: "A", payload: 33, series: "Y"}
];
msg.payload = m;
2. Time-Series Data (X/Y Coordinates)
For Line charts or charts requiring specific timestamps, provide an array of objects with x (timestamp) and y (value) keys.
var chart = [{
"series": ["A", "B", "C"],
"data": [
[{"x": 1504029632890, "y": 5}, {"x": 1504029636001, "y": 4}],
[{"x": 1504029633514, "y": 6}, {"x": 1504029636622, "y": 7}]
],
"labels": [""]
}];
msg.payload = chart;
3. Using topic for Series Identification
You can also use the msg.topic to identify a series when sending individual data points.
var m = [
{topic: "X", payload: 22},
{topic: "Y", payload: 66}
];
msg.payload = m;