# influxDB2 data + chart = error "Bad data inject"

**URL:** https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666
**Category:** Dashboard
**Created:** [21 April 2025 05:39 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666 "2025-04-21T05:39:22Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![just\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@just\_Alex](https://discourse.nodered.org/u/just_Alex)
#### Post date: [21 April 2025 05:39 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/1 "2025-04-21T05:39:22Z")

</div>

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:

```auto
from(bucket: "newnodered")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "temperature")

```

1. Created function node to check and correct data:

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

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

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

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 April 2025 05:50 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/2 "2025-04-21T05:50:14Z")

</div>

Hi Alex, welcome to the forum.

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

---

<div class="post-metadata">

### Author: ![just\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@just\_Alex](https://discourse.nodered.org/u/just_Alex)
#### Post date: [21 April 2025 06:29 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/3 "2025-04-21T06:29:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [21 April 2025 07:01 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/4 "2025-04-21T07:01:13Z")

</div>

The correct format would

```auto
[
    {
         "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](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md)

---

<div class="post-metadata">

### Author: ![just\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@just\_Alex](https://discourse.nodered.org/u/just_Alex)
#### Post date: [21 April 2025 07:55 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/5 "2025-04-21T07:55:20Z")

</div>

Thank you E1cid!  
Will try in the evening

---

<div class="post-metadata">

### Author: ![just\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@just\_Alex](https://discourse.nodered.org/u/just_Alex)
#### Post date: [21 April 2025 09:53 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/6 "2025-04-21T09:53:24Z")

</div>

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:

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

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

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 April 2025 10:09 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/7 "2025-04-21T10:09:02Z")

</div>

> [@just\_Alex](#):
>
> debug output is (data is in the past 30 minutes):
> 
> ```auto
> 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
> 
> ```

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

PS, as for your issue, look at the nested arrays of the `data` property in [the docs](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md#line-charts-1)

e.g..

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

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [21 April 2025 12:12 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/8 "2025-04-21T12:12:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![just\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@just\_Alex](https://discourse.nodered.org/u/just_Alex)
#### Post date: [21 April 2025 13:43 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/9 "2025-04-21T13:43:49Z")

</div>

**Steve-Mcl** , **E1cid** ,  
finally it works!

Thank you very-very much for your help! )

---

<div class="post-metadata">

### Author: ![just\_Alex](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@just\_Alex](https://discourse.nodered.org/u/just_Alex)
#### Post date: [21 April 2025 13:46 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/10 "2025-04-21T13:46:52Z")

</div>

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;

---

<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: [21 May 2025 13:47 UTC](https://discourse.nodered.org/t/influxdb2-data-chart-error-bad-data-inject/96666/11 "2025-05-21T13:47:43Z")

</div>

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