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

**URL:** <https://discourse.nodered.org/t/different-colors-for-3-chart-lines-works-but-not-always/96563>\
**Category:** Dashboard\
**Created:** [14 April 2025 12:20 UTC](https://discourse.nodered.org/t/different-colors-for-3-chart-lines-works-but-not-always/96563 "2025-04-14T12:20:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruffieuxh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ruffieuxh/32/63479_2.png) [@ruffieuxh](https://discourse.nodered.org/u/ruffieuxh)\
**Post date:** [14 April 2025 12:20 UTC](https://discourse.nodered.org/t/different-colors-for-3-chart-lines-works-but-not-always/96563/1 "2025-04-14T12:20:22Z")

</div>

Hi,

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/208b61af242ba190684e1b4787cf7d52bf7d6afd.png)

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).

```auto
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:

 ![Bildschirmfoto vom 2025-04-14 14-17-43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b47ac1e0d56ee5c73851aac4838fbc862ff0b0c6.png)

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 April 2025 12:40 UTC](https://discourse.nodered.org/t/different-colors-for-3-chart-lines-works-but-not-always/96563/2 "2025-04-14T12:40:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ruffieuxh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ruffieuxh/32/63479_2.png) [@ruffieuxh](https://discourse.nodered.org/u/ruffieuxh)\
**Post date:** [14 April 2025 13:23 UTC](https://discourse.nodered.org/t/different-colors-for-3-chart-lines-works-but-not-always/96563/3 "2025-04-14T13:23:53Z")

</div>

Ahhh......could have thought about this myself! 😊

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

Many thanks

Heinz

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [28 April 2025 13:24 UTC](https://discourse.nodered.org/t/different-colors-for-3-chart-lines-works-but-not-always/96563/4 "2025-04-28T13:24:07Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
