Different colors for 3 chart lines (works but not always)

Hi,

Based on some ideas in this forum, I created this chart:

It basically shows a orange line for the zero line, a green line, when my PV system is delivering power to the grid (pos values or "Einspeisung") and a yellow line, if my PV system is pulling power from the grid (neg values or "Bezug").

For this I implemented this code and get values every minute (single value pos or neg).

var Power = new Object();
var ZeroLine = new Object();
Power.payload = msg.payload;

if (Power.payload < 0) {
    Power.topic = "Bezug";
} else {
    Power.topic = "Einspeisung";
}

ZeroLine.payload = 0; 
ZeroLine.topic = "Zero";

return [Power, ZeroLine];

The chart node is configured as follows:

This works almost perfectly but sometimes the colors get mixed up between the lines and I do not understand why. Does anyone have an idea what the problem is?

Many thanks for your help
Heinz

The colours will be determined by the order that the topics arrive following startup. To ensure particular colours send a dummy set of messages on startup, one for each topic, with null values. Then the colours will be determined by that initial ordering.

1 Like

Ahhh......could have thought about this myself! :blush:

You saved me a hell of a lot of trial & error.

Many thanks

Heinz