Bar Graph not showing

Hello! I've been struggling with this one for a while. Already read a lot of topics but I cant get why it doesn't show info in a bar graph.

[{"id":"3e0b323b.87db66","type":"inject","z":"8195f5e6.5fdde8","name":"Timestamp","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":110,"y":620,"wires":[["e619e817.5db39"]]},{"id":"e619e817.5db39","type":"template","z":"8195f5e6.5fdde8","name":"Query Total","field":"topic","fieldType":"msg","format":"sql","syntax":"mustache","template":"SELECT DATE_FORMAT(dataLeitura,'%Y-%m-%d') dia,ifnull(round(sum(data),2),0) consumo \nFROM sensorReadings \nWHERE topic = 'casa/kwh'\nAND date(dataLeitura) >= subdate(now(),INTERVAL 5 DAY)\nGROUP BY date(dataLeitura);","output":"str","x":270,"y":620,"wires":[["b41e5140.2de518"]]},{"id":"b41e5140.2de518","type":"Stackhero-MySQL","z":"8195f5e6.5fdde8","server":"5643cdd4.526464","name":"","x":460,"y":620,"wires":[["311af654.23ae8a","a70a5c60.e1c9b8"]]},{"id":"a70a5c60.e1c9b8","type":"debug","z":"8195f5e6.5fdde8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":270,"y":760,"wires":[]},{"id":"311af654.23ae8a","type":"ui_chart","z":"8195f5e6.5fdde8","name":"Consumo Diário","group":"bc04c8c8.10dab","order":5,"width":0,"height":0,"label":"Consumo Diario","chartType":"bar","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"Consumo","dot":false,"ymin":"0","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":460,"y":680,"wires":[["a70a5c60.e1c9b8"]]},{"id":"5643cdd4.526464","type":"Stackhero-MySQL-Server","z":"","name":"sensorLog DB","host":"localhost","port":"3306","tls":false,"database":"sensorLog"},{"id":"bc04c8c8.10dab","type":"ui_group","z":"","name":"Geral","tab":"fc15d692.61a598","order":4,"disp":true,"width":"12","collapse":true},{"id":"fc15d692.61a598","type":"ui_tab","z":"","name":"Casa","icon":"fa-home","disabled":false,"hidden":false}]

I also tried with a prepare data node like this:

[{"id":"cc8c01f6.159158","type":"function","z":"8195f5e6.5fdde8","name":"Prepare Data","func":"var msg1 = {};\nlet dataH =[];\n\nfor (let X in msg.payload) \n{\n    dataH.push({\"x\":msg.payload[X].dia, \"y\":msg.payload[X].consumo});\n}\nmsg1.payload = [{\"series\":[\"Consumo\"], \"data\":[dataH],\"labels\": [\"Consumo\"]}];\nreturn (msg1);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":100,"y":660,"wires":[[]]}]

Any clues?

Thank you in advance.

At a Glance it looks like you are setting dashboard chart as bar chart, but feeding it line chart data format.

Hello, thank you for your reply.

I think I know what you mean, and I went to the page you refer.

Let me try to explain, this is what I get from the select on the database, I'm a newbie on Node Red, I think this is my payload, correct?

[{"dia":"2020-07-25","consumo":29.51},{"dia":"2020-07-26","consumo":31.8},{"dia":"2020-07-27","consumo":39.3},{"dia":"2020-07-28","consumo":24.03},{"dia":"2020-07-29","consumo":27.28}]

Isn't this enough for the Bar chart?

I thought I would get a bar for day 25 with value 29.51, and so on.

With this I get "Bad data inject"...

[{
    "series": [ "X", "Y", "Z"],
    "data": [[29.51], [31.8], [39.3]],
    "labels": ["2020-07-25", "2020-07-26", "2020-07-27"]
}]

try injecting that

Thanks again. From the page you sent I just saw the example in the bottom. I understood the example you are giving. I will try it.

Hi. was in a rush when posted the example. This is more correct.

[{
"series": ["Used"],
"data": [[29.51,31.8,39.3]],
"labels": ["2020-07-25","2020-07-26", "2020-07-27"]
}]

:grinning:

I've just had my first try at this and I think I'm in the good way. Yes, I also found out that the labels where misplaced

Screenshot from 2020-07-30 10-38-30

Thank you very much for your help. I will post here my solution, just have to make same adjustments.

So, this is my graph right now. I think it's stable.

Screenshot from 2020-07-30 11-30-59

The code I use is this:

let dataC = [[]];
let dataLabels = [];

for (let X in msg.payload) 
{
    dataLabels[X] = msg.payload[X].dia;
    dataC[0][X] = msg.payload[X].consumo;
}

var m={
    "series":["Consumo"],
    "data":dataC,
    "labels":dataLabels
};

return {payload:[m]};

Thanks for your help!!! :+1:

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