# Display datas from influxdb in an UI-Chart

**URL:** https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006
**Category:** Dashboard
**Created:** [31 December 2022 22:34 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006 "2022-12-31T22:34:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)
#### Post date: [31 December 2022 22:34 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/1 "2022-12-31T22:34:58Z")

</div>

Hi all,

Following up from a 2021 thread - [Display datas from influx in an UI-Chart](https://discourse.nodered.org/t/display-datas-from-influx-in-an-ui-chart/38579) - I need help with getting data from an Influxdb into a Bar Chart.

I am recording a daily total of Solar generated - one figure per day - which I simply want to chart the month.

I'm using the SQL query "SELECT solar FROM mydb". This extracts the timestamp and the solar data. Here is my data after processing it through my function

```auto
var series = ["Date"];
var labels = ["kWh"];
msg.payload.map(point => { return { x: point[0], y: point[1] } });
msg.payload = [{ series: series, data: [msg.payload], labels: labels }];
return msg;
```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a34861ce05f579bd8408a16ae0fb3539e989871f.png)

And apart from just saving the timestamp, I also saved the date in YYYY-MM-DD format in it's own field called "date", thinking that I could use the SQL query "SELECT date,solar FROM mydb" instead. But then, how would I use elements 1 and 2 instead of 0 and 1 ? The extracted data would look like this

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/7001c80d147988f786bca8cb921e880097451d6c.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [31 December 2022 23:02 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/2 "2022-12-31T23:02:21Z")

</div>

The db returns an array of objects, map loops through the array. You then would be working on the object `point`, not an array.  
I would probably do this

```auto
msg.payload = [
    {
        series: ["Date"],
        data: [msg.payload.map(point => { return { x: point.time, y: point.solar } })],
        labels: ["kWh"]
    }
]
return msg;

```

To do it your way you would assign your map of `payload` to a variable.

```auto
let series = ["Date"];
let labels = ["kWh"];
let data = msg.payload.map(point => { return { x: point.time, y: point.solar } });
msg.payload = [{ series: series, data: [data], labels: labels }];
return msg;

```

[edit] To format how the chart displays the ISO timestamp you can set that in the ui-chart node config.

---

<div class="post-metadata">

### Author: ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)
#### Post date: [31 December 2022 23:29 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/3 "2022-12-31T23:29:52Z")

</div>

> [@E1cid](#):
>
> ```auto
> let data = msg.payload.map(point => { return { x: point.time, y: point.solar } });
> msg.payload = [{ series: series, data: [data], labels: labels }];
> 
> ```

Great - nearly there. That gives me a perfect Line Graph - but what about for a Bar Chart ? It didn't display anything for it.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [31 December 2022 23:37 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/4 "2022-12-31T23:37:34Z")

</div>

One way

```auto
let series = ["kWh"];
let labels = msg.payload.map(point => point.time );
let data = msg.payload.map(point => point.solar);
msg.payload = [{ series: series, data: [data], labels: labels }];
return msg;

```

untested as i do not have your data.

---

<div class="post-metadata">

### Author: ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)
#### Post date: [1 January 2023 00:08 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/5 "2023-01-01T00:08:58Z")

</div>

Genius - Thank you

---

<div class="post-metadata">

### Author: ![championc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/championc/32/39754_2.png) [@championc](https://discourse.nodered.org/u/championc)
#### Post date: [1 January 2023 00:19 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/6 "2023-01-01T00:19:53Z")

</div>

Quick Question  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/4341109289c1e4e930e8eed02300c9bb844232ad.png)

Can I have all bars the one colour ? What would I need to change for this to happen ?

NOTE: I only have Solar data from 20/12/2022, so the chart is correct

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 January 2023 01:05 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/7 "2023-01-01T01:05:05Z")

</div>

If you look at all the settings in the ui-chart config or read the node help you may have noticed a check box or the read me links to chart array formats

> for bars of the same colour, set the flag `Use first colour for all bars` in the node configuration, and set labels for each column

> See **[this information](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md)** for how to pre-format data to be passed in as a complete chart.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [15 January 2023 01:05 UTC](https://discourse.nodered.org/t/display-datas-from-influxdb-in-an-ui-chart/73006/8 "2023-01-15T01:05:58Z")

</div>

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