influxDB2 data + chart = error "Bad data inject"

Hello everybody, I need your help!
I spent the whole sunday, but the problem persists:

  1. I'm writing data from mqtt to InfluxDB2.
  2. I created InfluxDB In node:
from(bucket: "newnodered")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "temperature")
  1. Created function node to check and correct data:
if (!Array.isArray(msg.payload)) {
    node.error("msg.payload is not an array");
    return null;
}

let points = msg.payload.map(item => {
    if (!item._time || typeof item._value === "undefined") {
        node.warn("missed incorrect data element");
        return null;
    }
    // convert time to ISO 8601
    let isoTime = new Date(item._time).toISOString(); // "2025-04-21T08:02:17.123Z"
    isoTime = isoTime.replace(/\.\d{3}Z$/, "Z");       // "2025-04-21T08:02:17Z"
    
    // convert value to a number
    let valueNum = Number(item._value);
    if (isNaN(valueNum)) {
        node.warn("value is not number: " + item._value);
        return null;
    }
    return { x: isoTime, y: valueNum };
}).filter(p => p !== null);

if (points.length === 0) {
    node.error("no correct data for chart");
    return null;
}

msg.payload = points;
return msg;

  1. And finally - Chart.
Type = line chart, 
X-axis Label = Automatic

And only see error: "Bad data inject"

As I can understand, data to chart is correct and in correct format?
Where's the issue?

msg.payload : array[2]
array[2]
0: object
x: "2025-04-21T04:40:05Z"
y: 3
1: object
x: "2025-04-21T04:46:21Z"
y: 3

Hi Alex, welcome to the forum.

Can you confirm which dashboard you are using & which version? (Look in palette manager)

Hello Steve!

sorry, missed: 1. node-red-dashboard 3.6.5.
And:
Node-RED version: v4.0.9
Node.js version: v20.19.0
Linux 6.1.31-sun50iw9 arm64 LE

The correct format would

[
    {
         "series":[
             "line_name"
         ],
         "data":[
              [     
                  {
                      "x": "2025-04-21T04:40:05Z",
                      "y": 3
                  },{
                      "x": "2025-04-21T04:46:21Z",
                      "y": 3
                  }
             ]
        ]
    }
]

more formats for dashboard 1 charts here node-red-dashboard/Charts.md at master · node-red/node-red-dashboard · GitHub

Thank you E1cid!
Will try in the evening

jE1cid

changed Function to meet the strtucture.

Error was gone, but chart is empty (no axis, no legends - only label).
Noticed, that in date debug is in future (my TZ is +3). Changed it to local - anyway chart is empty:

if (!Array.isArray(msg.payload)) {
    node.error("msg.payload is not an array");
    return null;
}
node.warn("Payload length: " + msg.payload.length);
let dataArray = msg.payload.map(item => {
    if (!item._time || typeof item._value === "undefined") {
        node.warn("missed element without _time or _value");
        return null;
    }
    // convert time from UTC то local
    let localTime = new Date(item._time).toLocaleString("ru-RU", { timeZone: "Europe/Moscow" });
    return {
        x: localTime,
        y: Number(item._value)
    };
}).filter(p => p !== null);
node.warn("dataArray length: " + dataArray.length);
msg.payload = [
    {
        series: ["line_name"],
        data: dataArray
    }
];
return msg;

debug output is (data is in the past 30 minutes):

msg.payload : array[1]
array[1]
0: object
series: array[1]
0: "line_name"
data: array[3]
0: object
x: "21.04.2025, 12:18:52"
y: 3
1: object
x: "21.04.2025, 12:18:54"
y: 3
2: object
x: "21.04.2025, 12:18:55"
y: 3

Chart properties are:

Type - line chart
X-axis = last 4 hours
X-axis Label = automatic

Where's my next issue?

Can you please use the "Copy Value" button to generate a JSON version of the data (it is easier to read that selecting text from the debug pane.

BX00Cy7yHi

PS, as for your issue, look at the nested arrays of the data property in the docs

e.g..

[{
"series": ["A"],
"data": [
    [
        { "x": 1504029632890, "y": 5 },
        { "x": 1504029636001, "y": 4 },
        { "x": 1504029638656, "y": 2 }
    ]
],
"labels": [""]
}]

The times do not look like ISO timestamps which you showed in previous post, maybe convert to ISO or millisecond unix timestamps, but most probably The issue Steve has shown ( i have fixed the example i showed.).

Best to supply an example minimal flow with attached data, as Steve has show how to get. This way we can run the flow and see the settings.

Steve-Mcl, E1cid,
finally it works!

Thank you very-very much for your help! )

I'm not sure the time correction is necessary, but I will check this later.
So, the code:

for (let i = 0; i < msg.payload.length; i++) {
let obj = msg.payload[i];
if (obj._value === null ||
obj._value === "" ) {
console.log(Zero: ${obj._value});
obj._value = 0;
}
obj._value = Number(obj._value);
console.log(Converted: ${obj._value});

// manual time correction (+3 hours)
if (obj._start) {
    const dateObj = new Date(obj._time);
    dateObj.setHours(dateObj.getHours() + 3); // +3 hours
    obj._time = dateObj.toISOString(); // saving back to ISO format

    const dateObj_start = new Date(obj._start);
    dateObj_start.setHours(dateObj_start.getHours() + 3); //+3 hours
    obj._start = dateObj_start.toISOString(); // saving back to ISO format

    const dateObj_stop = new Date(obj._stop);
    dateObj_stop.setHours(dateObj_stop.getHours() + 3); // +3 hours
    obj._stop = dateObj_stop.toISOString(); // saving back to ISO format

}

}
return msg;