Bad data inject [warning]

Hello friends, I have a warning " bad data inject " while I am importing data from DB and show it on bar chart. The point is all the process is done perfectly and also data represented correctly on bar chart but I don't understamd the source of this warning!

This is my imported data from DB:

[{"Date":"2023-04-12T22:00:00.000Z","Avg_var2":"73.0","Avg_var3":"61.0","Avg_var6":"11.0"},{"Date":"2023-04-13T22:00:00.000Z","Avg_var2":"73.0","Avg_var3":"61.0","Avg_var6":"11.0"},{"Date":"2023-04-16T22:00:00.000Z","Avg_var2":"73.0","Avg_var3":"61.0","Avg_var6":"11.0"},{"Date":"2023-04-17T22:00:00.000Z","Avg_var2":"73.0","Avg_var3":"61.0","Avg_var6":"11.0"},{"Date":"2023-04-18T22:00:00.000Z","Avg_var2":"73.0","Avg_var3":"61.0","Avg_var6":"11.0"},{"Date":"2023-04-19T22:00:00.000Z","Avg_var2":"73.0","Avg_var3":"61.0","Avg_var6":"11.0"}]

and I respect the chart format such this:

var bar = [{
  "series": [],
  "data": [],
  "labels": []
}];

let columns = 0;

for (var series in msg.payload[0]) {
  if (series !== "Date") {
    bar[0].series.push(series);
    bar[0].data.push([]);
    columns++;
  }
}

for (var j = 0; j < msg.payload.length; j++) {
  for (var i = 0; i < columns; i++) {
    bar[0].data[i].push( msg.payload[j][bar[0].series[i]]);
  }

  bar[0].labels.push(msg.payload[j].Date.toLocaleString('en-us', { weekday: 'short' }));
}

msg.payload = bar;

return msg;

and this is the final data injecting to chart:

[{"series":["Avg_var2","Avg_var3","Avg_var6"],
  "data":[["73.0","73.0","73.0","73.0","73.0","73.0"],
              ["61.0","61.0","61.0","61.0","61.0","61.0"],
              ["11.0","11.0","11.0","11.0","11.0","11.0"]],
 "labels":["Thu","Fri","Mon","Tue","Wed","Thu"]}]

As I mentioned this is the result :

and this is the warning I get

image

I would appreciate it if give me an idea to fix the problem.

Interesting. I have not used the dashboard chart for some time now, but I have some examples, and the output looks same as yours:

var m={
    "series":["X","Y","Z"],
    "data":[[5,6,9],[3,8,5],[6,7,2]],
    "labels":["Jan","Feb","Mar"]
};
return {payload:[m]};

Can you check if the above works for you?

The chart rejects incoming payload if those rules are not followed:

if (value[0].hasOwnProperty("series") && value[0].hasOwnProperty("data"))

where value[0] is (first) object in the array in msg.payload

You did show us case with positive outcome which is created from known and valid input. But is it always the case? The code doesn't validate the input thus there's not much of guarantee ...

Hi @nygma2004 , Thanks for your reply. I test your structure and I didn't see the warning but when I
put [] such this

var bar = [ {
                  "series": [],
                  "data"  : [],
                  "labels": []
} ];

The warning come up!

Just to be clear you do all correctly

This will produce error:

var bar = [{
    "series": [],
    "data": [],
    "labels": []
}];
msg.payload = [bar]
return msg;

Correct will be:

var bar = [{
    "series": [],
    "data": [],
    "labels": []
}];
msg.payload = bar
return msg;

Your data is correct and works for me with no errors, so i would think you are getting some miscellaneous payload messages being sent to chart. Would need to see your flow to be sure.

Hi, Thanks for your hint. Actually, yes you are right and the problem is coming from another input in parallel with function foarmet the data for chart. In this node I am trying to clean the chart when payload is empty :

var bar = {
    "series": [],
    "data": [],
    "labels": []
};

if (msg.payload == null) {
    bar.data = [];
}


return { payload: [bar] };

I am a bit confused :thinking :face_with_spiral_eyes:

To clear chart, send an empty array.

msg.payload = []

Send an empty array, e.g. msg.payload = [];

[edit] I see HotNipi already pointed the correct way to reset a chart.

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