Skip to content

Chart Line ​

The ui-chart-line widget plots one or two series as lines. The node can build the series itself: every numeric value found in the incoming objects is appended to a history kept per property path, up to a maximum number of points. It also accepts series prepared by the flow.

The header holds the title, a settings button and an expand button. The settings dialog has:

  • switches for Show title, Show legend, Normalize and Show stats, applied at once;
  • two selectors for the series to plot: the first one (the first series when nothing is chosen) and an optional second one;
  • the number of points to keep (5 to 1000, in steps of 5);
  • a cancel button and a save button, which applies the series selection and sends the selection and the number of points to the output.

With Normalize (on by default) each series is drawn as 0 to 100 % of its own range, so two series of different magnitudes share the axis; the tooltip shows the real value and the percentage. With Show stats (on by default) a panel beside the chart, or below it on narrow widgets, shows the average, minimum and maximum of each plotted series. The expand button opens the chart in a larger dialog with the Legend, Normalize and Stats switches. The switches are saved per widget in the browser and, once a viewer changes one, override the editor values in that browser.

The series selection is not saved: after a page reload the chart shows the first series again, until a viewer or the flow selects others (see Series selection). The first line is drawn in #2BB6D0 and the second in #E63b1f, unless the series has its own color. Without data the widget shows No data available.

Line chart

Palette: category Charts, label line chart. 1 input, 1 output.

Configuration ​

PropertyDescriptionDefault
NameNode name shown in the editor.""
GroupDashboard group where the chart is displayed.(required)
SizeWidget width and height; 0 means automatic.0 x 0
TitleText in the chart header. When empty, Parámetros.Parámetros
Show titleShows the title in the header.true
Show legendShows the legend above the chart.true
Nº of lines selector LabelNot used by the widget.Nº of lines
Var 2 selector labelLabel of the first series selector in the settings dialog. When empty, Variable 1.Variable 1
Var 1 selector labelLabel of the second series selector in the settings dialog. When empty, Variable 2.Variable 2
Nº of points to save labelLabel of the number of points field in the settings dialog. When empty, Nº of points to save.Nº of points to save
Save button labelText of the save button of the settings dialog. When empty, SAVE.SAVE

Input ​

The node looks at msg.payload in this order and uses the first case that applies.

History length ​

msg.payload.configLineChartLength (a positive number) sets how many points the history keeps per series. The default is 100, and the node returns to it when it restarts or is redeployed. Lowering the length drops the oldest points at once. The rest of the message is ignored.

js
msg.payload = { configLineChartLength: 300 };

Prepared series ​

When msg.payload has both variables and labels, the chart shows them as they are, without touching the history, and the message goes out on the output.

js
msg.payload = {
    variables: [
        { name: "Temperature", values: [22, 23, 24, 25, 26], color: "#2BB6D0" },
        { name: "Humidity", values: [60, 62, 65, 63, 64] }
    ],
    labels: ["10:00", "10:01", "10:02", "10:03", "10:04"]
};

Each variable needs name and values; variables without them are dropped. color is optional. labels are the X axis labels. Values to record and series selections received later redraw the chart from the history.

Clear ​

msg.payload = "reset", "clear" or { action: "clear" } deletes the history and empties the chart in every browser, and a message goes out on the output.

Values to record ​

Any other object is walked recursively. Each number, or string holding a number, is appended to the series named after its dot path, and the chart is redrawn:

js
msg.payload = { temperature: 22.4, press: { force: 812, speed: "35" } };
// appends to the series "temperature", "press.force" and "press.speed"
  • Arrays inside the object, booleans and other non-numeric values are skipped.
  • configViewport, configLineChartLength, configLineChart, configMasks and configTraining, and everything under them, are skipped.
  • Under a top-level tagCounter, only tagCounter.OK.count and tagCounter.NOK.count are recorded, and only when they are numbers.
  • The X axis is numbered 1, 2, ... Series are aligned by position, so a series that started later is shorter and ends before the others.

The history is kept in the node context: it survives a Node-RED restart only when a persistent context store is configured.

Series selection ​

msg.payload.configLineChart selects the plotted series by name in every open browser:

js
msg.payload = { configLineChart: { var1: "temperature", var2: "press.force" } };

var1 falls back to the first series when no series has that name. var2 is optional and is ignored when no series has that name or it equals var1. The number of lines follows from var2. Numeric values elsewhere in the same payload are recorded as usual.

Targeting one browser ​

A message that carries msg._client redraws only the browser it names; the history is still shared. Other messages update every open dashboard. The node adds itself to the dashboard's Accept Client Data list, so nothing has to be ticked there.

Output ​

WhenMessage
Prepared series received{ payload: <the received payload>, topic: "chart-update" }
Clear received{ payload: { action: "clear", variables: [], labels: [] } }, plus the _client of the received message if it had one
Save button pressed in the settings dialog{ payload: { nodesMaxLength: <points> } }
Save button pressed, on the first save after the page loads and whenever the selection changes{ payload: { lineConfig: { numberOfLines: 1, var1: "temperature", var2: null } } } (numberOfLines is 2 and var2 the second series name when two series are selected)

Recorded values, history lengths and series selections received on the input send nothing.

The save button does not change the history length, nor the series shown in other browsers, by itself: the flow has to send them back to the input as configLineChartLength and configLineChart. Do not wire the output straight to the input: nodesMaxLength and lineConfig.numberOfLines would be recorded as series. The number of points field shows 100 when the page loads and only follows the configLineChartLength messages received while the page is open, so nodesMaxLength can differ from the length the node uses.

Status and errors ​

Status or logWhen
Status, green dot: Max history: <length>The history length changed.
Warning: Invalid history length: <value>. Using default.configLineChartLength is negative or is not a number. The length is left as it was.
Error: Error sending data to socket: <message>The chart data could not be sent to the dashboard.

Usage example ​

A function node sends the figures of each inspection cycle:

js
// msg.payload from the inspection: { cycleMs: 412, temperature: 38.2, ... }
msg.payload = {
    cycleTime: msg.payload.cycleMs,
    temperature: msg.payload.temperature
};
return msg;

An inject node set to run once at start sends the JSON payload { "configLineChartLength": 500 }, so the chart keeps the last 500 cycles.

A second function node, wired from the chart output back to its input, makes the series a viewer saves in the settings dialog appear in every open dashboard:

js
if (msg.payload?.lineConfig) {
    const { var1, var2 } = msg.payload.lineConfig;
    return { payload: { configLineChart: { var1, var2 } } };
}
return null;