Temperature and epoch data from mysql and showing line chart problem

Hi

I fetching temperature and date(epoch) data from mysql database and i showing that on a line chart.
My problem is, on x-axis showing just the raw epoch data i unable the showind normal date. As you can see the y-axis looking good but on the x show epoch
image

In my function, i use this code as a input:

var data = [];
var month = [];
msg.payload.forEach(function(value) {

    data.push(value['temperature']);
    month.push(value['date']);
});

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

I tried this option too but i was worse

var data = [{"x":Date.parse(Date()), "y":Number(msg.payload)}];

I sendig the nodes code which are affected on my problem.

[{"id":"c56c1651.977188","type":"ui_chart","z":"b0a4e375.4b281","name":"Chart","group":"c90ed0b1.f8ac3","order":0,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"auto","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"1","removeOlderPoints":"1000","removeOlderUnit":"86400","cutout":"","useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"x":2090,"y":460,"wires":[[]]},{"id":"fd88f976.4ae028","type":"function","z":"b0a4e375.4b281","name":"Prep","func":"var data = [];\nvar month = [];\nvar minutes = 1000 * 60;\nvar hours = minutes * 60;\nmsg.payload.forEach(function(value) {\n\n    data.push(value['temperature']);\n    month.push(value['date']);\n});\n\n\n\n\nmsg.payload = [{\n     series: \"A\",\n    data: [data],\n    labels: month\n}];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1890,"y":340,"wires":[["c56c1651.977188","4c7a856b.6ad5bc"]]},{"id":"c3623688.d0dfa8","type":"mysql","z":"b0a4e375.4b281","mydb":"d0b63b56.52c6c8","name":"","x":1670,"y":360,"wires":[["fd88f976.4ae028","ed27559.8b8aaa8"]]},{"id":"4c7a856b.6ad5bc","type":"debug","z":"b0a4e375.4b281","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2150,"y":320,"wires":[]},{"id":"c90ed0b1.f8ac3","type":"ui_group","z":"","name":"Graphs","tab":"ebc81b8b.95c9e8","order":3,"disp":true,"width":"9","collapse":false},{"id":"d0b63b56.52c6c8","type":"MySQLdatabase","z":"","name":"","host":"127.0.0.1","port":"3306","db":"smh","tz":"","charset":"UTF8"},{"id":"ebc81b8b.95c9e8","type":"ui_tab","z":"b0a4e375.4b281","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Thank you for your answers !

What format do you wish the date/time to be?

HH:mm format

month.push(new Date(value['date']));

then in the chart node select
HH:mm as the x axis label

That's what i got:

image

show us the full function code, its hard to see throw a key hole.

1 Like

There it is

var data = [];
var month = [];
msg.payload.forEach(function(value) {

    data.push(value['temperature']);
    month.push(new Date(value['date']));
});

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

I will need to see a debug of the msg.payload going into the function.

1 Like

Series should be an array

1 Like

The debug node

var data = [];
var month = [];
msg.payload.forEach(function(value) {

    data.push({"y":value['temperature'],"x":new Date(value['date']).toISOString());
    
});

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

When i use that, i got this :
image

Try this
data.push({"y":value['temperature'],"x":parseInt(value['date']));

1 Like

It's working. Thank you very much !

Problem solved, thank you very much everyone who helped.

Kind of strange that the timestamp is stored/read as string at the DB.

1 Like

Yes that through me, i missed it was a string.

Its just temporay probably i will modify the field datatype

And then you can omit the parseInt and access the value['date'] directly

1 Like