If the data is in a mySQL table you first need to get the data into Node-RED
You will need to use one of the SQL nodes, if you google "SQL node-red" you should find a video and other guides to show you how to do this. Add a debug to the end of your flow so you can see the results you get.
Question is, what kind of chart you want to use. The structure of data is not same for all of them. Do you going to use ui_chart from dashboard or some external stuff?
So I hope you already tried something and you have something to show, flow or function where you try to rearrange your data into proper format to be feed to chart? If so, please share. Then we see where you stack and we can give you relevant help.
(just a gentle reminder that this forum is not a free coding resource, and that all contributors do so of their own free will and time. The general approach we prefer is one of education, where rather than provide canned answers, we help identify possible solutions and approaches based on the user's existing efforts, such that the whole community can help, contribute, and learn from others.)
Given the data you have provided you have two possible approaches. 1) rearrange the whole array into a chart format as per that doc. or 2) split the array and then resend each datapoint to the chart as if it was replayed - again as per that doc.
The second approach is possibly easier to start with - a split node will spit the array into individual objects - then a change node could move the various properties to match the required format for a line chart - then a function node with some code to convert the timestamp into epoch format.
I've noticed in the past that the chartjs library is smart enough to recognize and parse dates that come from database queries (or at least when they are in ISO-8601 format). So, I would try to send the data without converting the date/time strings first...
//var data = [[{"x":1537348236000,"y":2493},{"x":1537348326000,"y":2493}]];
//
var series =["Temperatur in °C", "x"];
var labels = ["Labels"];
var data = [];
var i, len, string;
for (i = 1, len = msg.payload.length, string = ""; i < len; i++) {
data.push({"x":Date.parse(msg.payload[i].timestamp) + 2*60*60, "y":Number(msg.payload[i].value)/100});
}
data = [data];
msg.payload = [{series, data, labels}];
return msg;
And here is the mySQL Query:
SELECT * FROM temperature ORDER BY timestamp DESC LIMIT 1440
Feel free to ask (or tell me what i could have done better).
Signed up just to say thank you for sharing this. Really useful, coming from languages other than JS.
Needed .length, .push and data = [data];
With those, anything is possible. Great question, good answer (in the end).
If I have time I'll see if I can make a more generic solution.