Convert object from sqlite to use in line graph

Need help,

I have a Select command from a Sqlite database that gave me the following timestamp and temp values:

[{"TIMESTAMP":1691538694000,"TEMP":"91.63"},{"TIMESTAMP":1691538699000,"TEMP":"91.67"},{"TIMESTAMP":1691538705000,"TEMP":"91.74"},{"TIMESTAMP":1691538712000,"TEMP":"91.76"},{"TIMESTAMP":1691538716000,"TEMP":"91.76"},

I need to be able to be able to convert it to display on a line graph. Any help will be appreciate

Thanks

Assuming that you are using node-red-dashboard v1...

You need to send your data to the chart node in a specific format:
An array containing a single object with properties "series", "data" and "labels".

  • "series" is an array of the names of lines on the chart. For a single line, just one element in the array.
  • "data" is an array of arrays, one array per line on the chart. Each array element is an object with x and y properties to define the points on the line.
  • "labels" - Actually I'm not sure what labels does, but it is an array of strings, in my experience always an array of one element, an empty string.
[{
"series": ["Series Name"],
"data": [
    [{ "x": 1504029634400, "y": 7 },
     { "x": 1504029637959, "y": 7 },
     { "x": 1504029640317, "y": 7 }
    ]
],
"labels": [""]
}]

You can make the task a bit simpler by tweeking your SQL select statement to return an array of objects with x and y properties - the heart of the "data" array (not tested)
Instead of SELECT timestamp, temp FROM table
SELECT timestamp AS x, temp AS y FROM table

[{"x":1691538694000,"y":"91.63"},{"x":1691538699000,"y":"91.67"},{"x":1691538705000,"y":"91.74"},{"x":1691538712000,"y":"91.76"},{"x":1691538716000,"y":"91.76"}]

Then feed the SQLite output into a function node to format it for the chart

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

The resulting chart

1 Like

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