Ui-chart is empty

My ui-chart stays empty. These are my Data:

{"labels":["2025-03-16T11:39:48.375Z","2025-03-16T12:39:48.395Z","2025-03-16T13:39:48.406Z","2025-03-16T14:39:48.417Z","2025-03-16T15:39:48.436Z","2025-03-16T16:39:48.451Z","2025-03-16T17:39:48.470Z","2025-03-16T18:39:48.478Z","2025-03-16T19:39:48.496Z","2025-03-16T20:39:48.513Z","2025-03-16T21:39:48.532Z","2025-03-16T22:39:48.552Z","2025-03-16T23:39:48.558Z","2025-03-17T00:39:48.572Z","2025-03-17T01:39:48.580Z","2025-03-17T02:39:48.593Z","2025-03-17T03:39:48.600Z","2025-03-17T04:39:48.613Z","2025-03-17T05:39:48.622Z","2025-03-17T06:39:48.716Z"],"series":[[324,321.8,326.8,332.2,324.7,325.1,330.4,322.4,322,66.9,65.8,66.9,67.7,65.3,68.4,66.6,64.8,65.3,68,66.4]]}

Flow:

[
    {
        "id": "36fa3994398c3c99",
        "type": "tab",
        "label": "Datenaufnahme",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "fb0560e6fbaf9f57",
        "type": "inject",
        "z": "36fa3994398c3c99",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "3600",
        "crontab": "",
        "once": false,
        "onceDelay": "300",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 190,
        "y": 180,
        "wires": [
            [
                "a59ecdd3cf7436d4"
            ]
        ]
    },
    {
        "id": "a59ecdd3cf7436d4",
        "type": "function",
        "z": "36fa3994398c3c99",
        "name": "Abfrage der Werte",
        "func": "\n// 🌡 Werte abrufen\nlet leistung = global.get(\"Leistung\") || 0;\n\n\n\n// 🕒 Zeitstempel generieren\nlet timestamp = new Date().toISOString();\n\n// 📄 CSV-Zeile erstellen\nmsg.payload = `${timestamp},${leistung}\\n`;\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 180,
        "wires": [
            [
                "c9bac3d96d3bd19e"
            ]
        ]
    },
    {
        "id": "c9bac3d96d3bd19e",
        "type": "file",
        "z": "36fa3994398c3c99",
        "name": "",
        "filename": "C:\\Users\\Labor\\Desktop\\messwert.csv",
        "filenameType": "str",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 770,
        "y": 180,
        "wires": [
            []
        ]
    },
    {
        "id": "b8635a54e085e25b",
        "type": "inject",
        "z": "36fa3994398c3c99",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "3600",
        "crontab": "",
        "once": false,
        "onceDelay": "300",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 190,
        "y": 260,
        "wires": [
            [
                "853caafa45a3ed6a"
            ]
        ]
    },
    {
        "id": "7cb7dff101dec369",
        "type": "function",
        "z": "36fa3994398c3c99",
        "name": "function 3",
        "func": "let rawData = msg.payload; // JSON-Daten\n\n// Sicherstellen, dass rawData ein Array ist\nlet dataArray = Array.isArray(rawData) ? rawData : [rawData];\n\n// Initialisiere das Dataset für den Chart\nlet dataset = {\n    labels: [],\n    series: [[]]  // Leistung\n};\n\n// Letzte 50 Werte übernehmen\nlet lastEntries = dataArray.slice(-20);\n\nlastEntries.forEach(entry => {\n    if (typeof entry === \"object\" && entry.timestamp && entry.leistung !== undefined) {\n        dataset.labels.push(entry.timestamp);  // ✅ Korrekt: Zeitstempel extrahieren\n        dataset.series[0].push(parseFloat(entry.leistung));  // ✅ Leistung\n    } else {\n        node.warn(\"⚠️ Ungültige Daten: \" + JSON.stringify(entry));\n    }\n});\n\nmsg.payload = dataset;\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 960,
        "y": 260,
        "wires": [
            [
                "a330ecd6d7a88ca6",
                "cda824069da2144a"
            ]
        ]
    },
    {
        "id": "853caafa45a3ed6a",
        "type": "file in",
        "z": "36fa3994398c3c99",
        "name": "",
        "filename": "C:\\Users\\Labor\\Desktop\\messwert.csv",
        "filenameType": "str",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "utf8",
        "allProps": false,
        "x": 490,
        "y": 260,
        "wires": [
            [
                "38f0994dc9c1ccf4"
            ]
        ]
    },
    {
        "id": "38f0994dc9c1ccf4",
        "type": "csv",
        "z": "36fa3994398c3c99",
        "name": "csv zu JSON",
        "spec": "rfc",
        "sep": ",",
        "hdrin": "",
        "hdrout": "none",
        "multi": "mult",
        "ret": "\\r\\n",
        "temp": "timestamp,leistung,luftfeuchte,temperatur",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": "",
        "x": 770,
        "y": 260,
        "wires": [
            [
                "7cb7dff101dec369"
            ]
        ]
    },
    {
        "id": "a330ecd6d7a88ca6",
        "type": "debug",
        "z": "36fa3994398c3c99",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1180,
        "y": 380,
        "wires": []
    },
    {
        "id": "cda824069da2144a",
        "type": "ui_chart",
        "z": "36fa3994398c3c99",
        "name": "",
        "group": "72214d4980ae2e55",
        "order": 2,
        "width": 0,
        "height": 0,
        "label": "chart",
        "chartType": "line",
        "legend": "true",
        "xformat": "auto",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": true,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1250,
        "y": 260,
        "wires": [
            []
        ]
    },
    {
        "id": "8553351e581deca0",
        "type": "ui_spacer",
        "z": "36fa3994398c3c99",
        "name": "spacer",
        "group": "72214d4980ae2e55",
        "order": 4,
        "width": 1,
        "height": 1
    },
    {
        "id": "0b082a4e23d14bae",
        "type": "ui_spacer",
        "z": "36fa3994398c3c99",
        "name": "spacer",
        "group": "72214d4980ae2e55",
        "order": 4,
        "width": 1,
        "height": 1
    },
    {
        "id": "72214d4980ae2e55",
        "type": "ui_group",
        "name": "Graph",
        "tab": "7d7df438f2fb4675",
        "order": 4,
        "disp": true,
        "width": 6,
        "collapse": false,
        "className": ""
    },
    {
        "id": "7d7df438f2fb4675",
        "type": "ui_tab",
        "name": "Microgreens Zelt",
        "icon": "dashboard",
        "order": 7,
        "disabled": false,
        "hidden": false
    }
]

Not enogh info to help you.
which dashboard node?
how is it configured?

Maybe export an example flow with data in an inject node, so we can see the issue.

How to import/export a flow

In order to make code readable and usable on the forum it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

See this post for more details - How to share code or flow json

1 Like

The data needs to be in this format

[
    {
        "series": [
            "name of series"
        ],
        "data": [
            [
                {
                    "x": "2025-03-16T11:39:48.375Z",
                    "y": 324
                },
                {
                    "x": "2025-03-16T12:39:48.395Z",
                    "y": 321.8
                },
                {
                    "x": "2025-03-16T13:39:48.406Z",
                    "y": 326.8
                },
                {
                    "x": "2025-03-16T14:39:48.417Z",
                    "y": 332.2
                },
                {
                    "x": "2025-03-16T15:39:48.436Z",
                    "y": 324.7
                },
                {
                    "x": "2025-03-16T16:39:48.451Z",
                    "y": 325.1
                },
                {
                    "x": "2025-03-16T17:39:48.470Z",
                    "y": 330.4
                },
                {
                    "x": "2025-03-16T18:39:48.478Z",
                    "y": 322.4
                },
                {
                    "x": "2025-03-16T19:39:48.496Z",
                    "y": 322
                },
                {
                    "x": "2025-03-16T20:39:48.513Z",
                    "y": 66.9
                },
                {
                    "x": "2025-03-16T21:39:48.532Z",
                    "y": 65.8
                },
                {
                    "x": "2025-03-16T22:39:48.552Z",
                    "y": 66.9
                },
                {
                    "x": "2025-03-16T23:39:48.558Z",
                    "y": 67.7
                },
                {
                    "x": "2025-03-17T00:39:48.572Z",
                    "y": 65.3
                },
                {
                    "x": "2025-03-17T01:39:48.580Z",
                    "y": 68.4
                },
                {
                    "x": "2025-03-17T02:39:48.593Z",
                    "y": 66.6
                },
                {
                    "x": "2025-03-17T03:39:48.600Z",
                    "y": 64.8
                },
                {
                    "x": "2025-03-17T04:39:48.613Z",
                    "y": 65.3
                },
                {
                    "x": "2025-03-17T05:39:48.622Z",
                    "y": 68
                },
                {
                    "x": "2025-03-17T06:39:48.716Z",
                    "y": 66.4
                }
            ]
        ]
    }
]

There is a link in the sidebar help text that shows the formats for different charts node-red-dashboard/Charts.md at master · node-red/node-red-dashboard · GitHub

[edit] As you mention live data you could just feed the live msg.payload and the series name in msg.topic, which will plot the data in real time. The chart node wil output the data for the chart configured time period or points, you can save this data for reloading the chart data on restart etc.

1 Like

So this is my code now:

[
    {
        "id": "36fa3994398c3c99",
        "type": "tab",
        "label": "Datenaufnahme",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "fb0560e6fbaf9f57",
        "type": "inject",
        "z": "36fa3994398c3c99",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "300",
        "crontab": "",
        "once": false,
        "onceDelay": "1",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 190,
        "y": 180,
        "wires": [
            [
                "a59ecdd3cf7436d4"
            ]
        ]
    },
    {
        "id": "a59ecdd3cf7436d4",
        "type": "function",
        "z": "36fa3994398c3c99",
        "name": "Abfrage der Werte",
        "func": "\n// 🌡 Werte abrufen\nlet leistung = global.get(\"Leistung\") || 0;\nlet luftfeuchteZelt = global.get(\"luftfeuchteZelt\") || 0;\nlet temperatur = global.get(\"temperatur_Zelt\") || 0;\n\n\n\n// 🕒 Zeitstempel generieren\nlet timestamp = new Date().toISOString();\n\n// 📄 CSV-Zeile erstellen\nmsg.payload = `${timestamp},${leistung},${luftfeuchteZelt},${temperatur}\\n`;\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 180,
        "wires": [
            [
                "c9bac3d96d3bd19e"
            ]
        ]
    },
    {
        "id": "c9bac3d96d3bd19e",
        "type": "file",
        "z": "36fa3994398c3c99",
        "name": "",
        "filename": "C:\\Users\\Labor\\Desktop\\messwert.csv",
        "filenameType": "str",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 770,
        "y": 180,
        "wires": [
            []
        ]
    },
    {
        "id": "b8635a54e085e25b",
        "type": "inject",
        "z": "36fa3994398c3c99",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "3600",
        "crontab": "",
        "once": false,
        "onceDelay": "300",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 190,
        "y": 260,
        "wires": [
            [
                "853caafa45a3ed6a"
            ]
        ]
    },
    {
        "id": "7cb7dff101dec369",
        "type": "function",
        "z": "36fa3994398c3c99",
        "name": "function 3",
        "func": "let rawData = msg.payload; // JSON-Daten\n\n// Sicherstellen, dass rawData ein Array ist\nlet dataArray = Array.isArray(rawData) ? rawData : [rawData];\n\n// Letzte 20 Werte übernehmen\nlet lastEntries = dataArray.slice(-20);\n\n// Initialisiere das neue Format für den Chart\nlet dataset = [\n    {\n        series: [\"Leistung\"],\n        data: [[]]\n    },\n    {\n        series: [\"Luftfeuchte\"],\n        data: [[]]\n    },\n    {\n        series: [\"Temperatur\"],\n        data: [[]]\n    }\n];\n\n// Daten umwandeln\nlastEntries.forEach(entry => {\n    if (typeof entry === \"object\" && entry.timestamp && entry.leistung !== undefined\n        && entry.luftfeuchteZelt !== undefined && entry.temperatur !== undefined) {\n\n        let timestamp = new Date(entry.timestamp).toISOString(); // ISO-Format sicherstellen\n\n        dataset[0].data[0].push({ x: timestamp, y: parseFloat(entry.leistung) });\n        dataset[1].data[0].push({ x: timestamp, y: parseFloat(entry.luftfeuchteZelt) });\n        dataset[2].data[0].push({ x: timestamp, y: parseFloat(entry.temperatur) });\n\n    } else {\n        node.warn(\"⚠️ Ungültige Daten: \" + JSON.stringify(entry));\n    }\n});\n\nmsg.payload = dataset;\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 960,
        "y": 260,
        "wires": [
            [
                "cda824069da2144a",
                "36120c3a59f765ad"
            ]
        ]
    },
    {
        "id": "853caafa45a3ed6a",
        "type": "file in",
        "z": "36fa3994398c3c99",
        "name": "",
        "filename": "C:\\Users\\Labor\\Desktop\\messwert.csv",
        "filenameType": "str",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "utf8",
        "allProps": false,
        "x": 490,
        "y": 260,
        "wires": [
            [
                "38f0994dc9c1ccf4"
            ]
        ]
    },
    {
        "id": "38f0994dc9c1ccf4",
        "type": "csv",
        "z": "36fa3994398c3c99",
        "name": "csv zu JSON",
        "spec": "rfc",
        "sep": ",",
        "hdrin": "",
        "hdrout": "none",
        "multi": "mult",
        "ret": "\\r\\n",
        "temp": "timestamp,leistung,luftfeuchte,temperatur",
        "skip": "0",
        "strings": true,
        "include_empty_strings": false,
        "include_null_values": "",
        "x": 770,
        "y": 260,
        "wires": [
            [
                "7cb7dff101dec369"
            ]
        ]
    },
    {
        "id": "cda824069da2144a",
        "type": "ui_chart",
        "z": "36fa3994398c3c99",
        "name": "",
        "group": "72214d4980ae2e55",
        "order": 1,
        "width": 6,
        "height": 4,
        "label": "chart",
        "chartType": "line",
        "legend": "true",
        "xformat": "auto",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": true,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1250,
        "y": 260,
        "wires": [
            []
        ]
    },
    {
        "id": "36120c3a59f765ad",
        "type": "debug",
        "z": "36fa3994398c3c99",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1140,
        "y": 500,
        "wires": []
    },
    {
        "id": "f7c125d9fc6e4141",
        "type": "ui_spacer",
        "z": "36fa3994398c3c99",
        "name": "spacer",
        "group": "5e394c4017bbf6d7",
        "order": 9,
        "width": 7,
        "height": 1
    },
    {
        "id": "4f661c201c5d4dbb",
        "type": "ui_spacer",
        "z": "36fa3994398c3c99",
        "name": "spacer",
        "group": "bdf1b59fa38ffb73",
        "order": 4,
        "width": 4,
        "height": 1
    },
    {
        "id": "2f33477fd01c63fd",
        "type": "ui_spacer",
        "z": "36fa3994398c3c99",
        "name": "spacer",
        "group": "bdf1b59fa38ffb73",
        "order": 6,
        "width": 4,
        "height": 1
    },
    {
        "id": "d20ceeb833a3352a",
        "type": "ui_spacer",
        "z": "36fa3994398c3c99",
        "name": "spacer",
        "group": "bdf1b59fa38ffb73",
        "order": 10,
        "width": 4,
        "height": 1
    },
    {
        "id": "d60bed6561f1d023",
        "type": "ui_spacer",
        "z": "36fa3994398c3c99",
        "name": "spacer",
        "group": "bdf1b59fa38ffb73",
        "order": 12,
        "width": 4,
        "height": 1
    },
    {
        "id": "72214d4980ae2e55",
        "type": "ui_group",
        "name": "Graph",
        "tab": "7d7df438f2fb4675",
        "order": 4,
        "disp": true,
        "width": 6,
        "collapse": false,
        "className": ""
    },
    {
        "id": "5e394c4017bbf6d7",
        "type": "ui_group",
        "name": "Klima",
        "tab": "7d7df438f2fb4675",
        "order": 1,
        "disp": false,
        "width": "14",
        "collapse": false,
        "className": ""
    },
    {
        "id": "bdf1b59fa38ffb73",
        "type": "ui_group",
        "name": "Beleuchtung",
        "tab": "7d7df438f2fb4675",
        "order": 2,
        "disp": true,
        "width": "14",
        "collapse": false,
        "className": ""
    },
    {
        "id": "7d7df438f2fb4675",
        "type": "ui_tab",
        "name": "Microgreens Zelt",
        "icon": "dashboard",
        "order": 7,
        "disabled": false,
        "hidden": false
    }
]

Ich bekomme diese Warnung:
:warning: Ungültige Daten: {"timestamp":"2025-03-17T11:09:59.783Z","leistung":326.7,"luftfeuchte":54.7,"temperatur":21.6}

Und mein Debug nach meiner Funktion gibt das aus:
[{"series":["Leistung"],"data":[]},{"series":["Luftfeuchte"],"data":[]},{"series":["Temperatur"],"data":[]}]

Welcome to the forum @GBROKO.

It looks like you are using the original Node-red dashboard, aka "DB1" (node-red-dashboard), and the data format @E1cid advises is for this dashboard.
However, node-red-dashboard is now unsupported. If you don't already have a considerable investment in DB1, you really ought to switch to the new dashboard "DB2" (@flowfuse/node-red-dashboard).
The chart node in DB2 is very different. In many ways it is simpler to format the data for it.

You seem to be getting data from a global context variable "Leistung" and appending it to a CSV file, then reading from that file to build your chart.
Generally, global context and the use of temporary files result in a Node-red flow vulnerable to unexpected results.
I suspect you would be better sending individual data points to the chart directly, thus getting a live data chart.

1 Like