# Can ui\_chart import data from a database?

**URL:** <https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154>\
**Category:** Dashboard\
**Created:** [23 November 2018 19:42 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154 "2018-11-23T19:42:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [23 November 2018 19:42 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154/1 "2018-11-23T19:42:30Z")

</div>

Hi,

I have a sqlite database with gas and electric multiple readings for each day.

I now want to display these in a graph,can **ui\_chart** somehow import these and display them ?  
If possible a datepicker would be use in the future.

Any thoughts or ideas welcome !

Thanks

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 November 2018 21:19 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154/2 "2018-11-23T21:19:10Z")

</div>

The ui chart can't import data, but you can get the data out of the db and send it to the chart. If you look at the Info tab for the chart node you will find a link to more information which tells you the format of the data you must give it to draw a chart from historical data.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [23 November 2018 21:19 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154/3 "2018-11-23T21:19:59Z")

</div>

OK thanks Colin

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 November 2018 21:23 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154/4 "2018-11-23T21:23:57Z")

</div>

Though I would say that if the ability to draw historical charts is a significant factor then I strongly suggest you look at influxdb and grafana which can easily be integrated with node-red and give very flexible historical (and real-time) graphs.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [23 November 2018 21:25 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154/5 "2018-11-23T21:25:04Z")

</div>

OK that's good to know , i will look tomorrow

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [25 November 2018 08:47 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154/6 "2018-11-25T08:47:47Z")

</div>

Hi,

Unfortunately I cannot use grafana as I am using a 32bit PC.  
So I have come back to trying to get database data into **ui\_chart node.**

I have spent all off yesterday to try and understand how to do this, but have not been successful in finding an answer although I have tried many ways !

Firstly I cannot find out what format the ui\_chart node requires the data to be formatted as ?

I am using an old version of NodeRED (at the moment everything has been working for years, so do not want to change at this moment, I will in the future)

![12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7230a7f32e3baeaf53c8d1526a8f3f75acce6c49.jpeg)

Keeping things simple I did get this to update a chart

 ![15](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/04e2e163ae6297c060ecc78446dbb541be53e609.jpeg)  
.  
.  
.  
.  
.

My NodeRED is connected like this....

 ![41](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c5a30df16a3c8cb22e983c9984365232205bae06.jpeg)

But gave this result

 ![43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9c1ec35f142b4c58ac13855037473d4f4772f2b7.jpeg)  
.

.

.  
Any help would be appreciated as I learn best from mistakes, instead of just copying and pasting.

Thanks

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 November 2018 10:08 UTC](https://discourse.nodered.org/t/can-ui-chart-import-data-from-a-database/5154/7 "2018-11-25T10:08:50Z")

</div>

1. since you ae on an old version of NR your results will be different than what I see using v0.19.5 - you realu should upgrade.

In the current release, the result of an SQL query is an array of all the rows that match the result. For example:

```auto
object
_msgid: "5e5286b2.7cc468"
topic: "select * from dhtreadings"
payload: array[3]
  0: object
    id: 1
    temperature: 22.4
    humidity: 48
    currentdate: "2018-11-25"
    currenttime: "10:00:46"
    device: "manual"
  1: object
  2: object
    id: 3
    temperature: 22.4
    humidity: 48
    currentdate: "2018-11-25"
    currenttime: "10:00:49"
    device: "manual" 

```

So the data is there, you will just have to figure out how to access the data in msg.payload in the old release you are using. you might try pushing it thru a json node...but I would recommend backing up your system and migrating to the currrent release.
