How to show old and current values in same chart

Boah - what a coding! @E1cid you are a huge expert :). I'll never find such a code, but I can read it.

Your example works, but didn't update the "Old power" to the last period. I found the way. :slight_smile:

But one thing may be messy: My function node to store current values. (I can't use the output of the chart, because there the time is adjusted to the past.)

I'm sure you now how to transfer my function node to the change node "change for new data", or a seperate one.

I have in general trouble using JSONate. I found this description and this simulator, but it seems to be different the usage in Node-Red. e.g. your expression $number($moment().format("x")) will not work inside the simulator and the functions are not mentioned in the description.

Here is now my working flow, just reduced to a timeframe of 1 minute:

[
    {
        "id": "8a701c96ea9f2909",
        "type": "ui_chart",
        "z": "d1395164b4eec73e",
        "name": "PV-Verlauf",
        "group": "1234abcd",
        "order": 0,
        "width": 0,
        "height": 0,
        "label": "PV-Verlauf",
        "chartType": "line",
        "legend": "true",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": "60",
        "removeOlderPoints": "",
        "removeOlderUnit": "1",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#ff7f0e",
            "#2ca02c",
            "#d62728",
            "#9467bd",
            "#8c564b",
            "#e377c2",
            "#7f7f7f",
            "#bcbd22"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 910,
        "y": 720,
        "wires": [
            [
                "c978733bb177459d"
            ]
        ]
    },
    {
        "id": "c978733bb177459d",
        "type": "debug",
        "z": "d1395164b4eec73e",
        "name": "chart",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1090,
        "y": 720,
        "wires": []
    },
    {
        "id": "5f2e29a7c869120d",
        "type": "change",
        "z": "d1395164b4eec73e",
        "name": "change old data to latest",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Old power",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "(\t   [\t       {\t           \"series\": [\"Old Power\", \"New Power\"],\t           \"data\": [\t               [],\t               []       \t           ]  \t       }\t   ]\t)",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload[0].data[0]",
                "pt": "msg",
                "to": "old",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "old",
                "pt": "flow",
                "to": "[]",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 610,
        "y": 640,
        "wires": [
            [
                "8a701c96ea9f2909",
                "c3cfad7bb9e4bca0"
            ]
        ]
    },
    {
        "id": "c3cfad7bb9e4bca0",
        "type": "debug",
        "z": "d1395164b4eec73e",
        "name": "old",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1090,
        "y": 640,
        "wires": []
    },
    {
        "id": "983fe8d85b3f4283",
        "type": "inject",
        "z": "d1395164b4eec73e",
        "name": "every 5 sec",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "timestamp",
                "v": "$number($moment().format(\"x\"))",
                "vt": "jsonata"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "5",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "New power",
        "payload": "$round($random(), 3)",
        "payloadType": "jsonata",
        "x": 230,
        "y": 720,
        "wires": [
            [
                "c81038ead8d5b188"
            ]
        ]
    },
    {
        "id": "53e8601545abab1f",
        "type": "inject",
        "z": "d1395164b4eec73e",
        "name": "reset chart",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[]",
        "payloadType": "json",
        "x": 220,
        "y": 780,
        "wires": [
            [
                "8a701c96ea9f2909"
            ]
        ]
    },
    {
        "id": "c1a991f3a8115cd3",
        "type": "change",
        "z": "d1395164b4eec73e",
        "name": "init chart",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "(\t   $fiveminsago := $number($moment().subtract(1,\"minute\").format(\"x\"));\t   [\t       {\t           \"series\": [\"Old Power\", \"New Power\"],\t           \"data\": [\t               [\t                   [\t                       0,\t                       1,\t                       2,\t                       3,\t                       4,\t                       5,\t                       6,\t                       7,\t                       8,\t                       9,\t                       10,\t                       11\t                   ].{\"x\": $fiveminsago + ($ * 60000), \"y\": $round($random(), 3)}            \t               ],[]       \t           ]  \t       }\t   ]\t)",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 660,
        "y": 580,
        "wires": [
            [
                "8a701c96ea9f2909",
                "40c6c0e3ffcb57eb"
            ]
        ]
    },
    {
        "id": "5fb141bc640dce0d",
        "type": "switch",
        "z": "d1395164b4eec73e",
        "name": "",
        "property": "old",
        "propertyType": "flow",
        "rules": [
            {
                "t": "null"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 410,
        "y": 600,
        "wires": [
            [
                "c1a991f3a8115cd3"
            ],
            [
                "5f2e29a7c869120d"
            ]
        ]
    },
    {
        "id": "40c6c0e3ffcb57eb",
        "type": "debug",
        "z": "d1395164b4eec73e",
        "name": "init",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1070,
        "y": 580,
        "wires": []
    },
    {
        "id": "c81038ead8d5b188",
        "type": "function",
        "z": "d1395164b4eec73e",
        "name": "save value",
        "func": "let old = flow.get(\"old\") || [];\n\nlet value = {x:msg.timestamp, y:msg.payload};\nold.push(value);\nflow.set(\"old\",old);\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 720,
        "wires": [
            [
                "8d08e21e3af47f2a",
                "91ca458babbf9511"
            ]
        ]
    },
    {
        "id": "8d08e21e3af47f2a",
        "type": "change",
        "z": "d1395164b4eec73e",
        "name": "change for new data",
        "rules": [
            {
                "t": "set",
                "p": "timestamp",
                "pt": "msg",
                "to": "$number($moment().subtract(1 ,\"minute\").format(\"x\"))",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "New Power",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 654,
        "y": 716,
        "wires": [
            [
                "8a701c96ea9f2909",
                "717ec4894c0aeea8"
            ]
        ]
    },
    {
        "id": "9f734376fdca9d9b",
        "type": "inject",
        "z": "d1395164b4eec73e",
        "name": "every minute",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 240,
        "y": 600,
        "wires": [
            [
                "5fb141bc640dce0d"
            ]
        ]
    },
    {
        "id": "717ec4894c0aeea8",
        "type": "debug",
        "z": "d1395164b4eec73e",
        "name": "time",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "timestamp",
        "targetType": "msg",
        "statusVal": "timestamp",
        "statusType": "auto",
        "x": 864,
        "y": 796,
        "wires": []
    },
    {
        "id": "91ca458babbf9511",
        "type": "debug",
        "z": "d1395164b4eec73e",
        "name": "time",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "timestamp",
        "targetType": "msg",
        "statusVal": "timestamp",
        "statusType": "auto",
        "x": 670,
        "y": 800,
        "wires": []
    },
    {
        "id": "1234abcd",
        "type": "ui_group",
        "name": "PV-Anlage",
        "tab": "494ffd2f5ab44ab2",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "494ffd2f5ab44ab2",
        "type": "ui_tab",
        "name": "Dashboard",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

BTW: How can I post the flow in one line? I read this post, but the link for description of how to post a flow is broken.