# Convert object from sqlite to use in line graph

**URL:** <https://discourse.nodered.org/t/convert-object-from-sqlite-to-use-in-line-graph/85906>\
**Category:** General\
**Tags:** database, function-node\
**Created:** [26 February 2024 02:20 UTC](https://discourse.nodered.org/t/convert-object-from-sqlite-to-use-in-line-graph/85906 "2024-02-26T02:20:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [26 February 2024 03:42 UTC](https://discourse.nodered.org/t/convert-object-from-sqlite-to-use-in-line-graph/85906/2 "2024-02-26T03:42:23Z")

</div>

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.

```auto
[{
"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`

```auto
[{"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

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

```

The resulting chart

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/9/29cc90efe36826b4c2cae339fdf59fbab3a95c57.png)

---

_[View the full topic](https://discourse.nodered.org/t/convert-object-from-sqlite-to-use-in-line-graph/85906)._
