# Build charts with data from mysql database

**URL:** <https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451>\
**Category:** General\
**Created:** [28 May 2020 18:49 UTC](https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451 "2020-05-28T18:49:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![node96](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@node96](https://discourse.nodered.org/u/node96)\
**Post date:** [28 May 2020 18:49 UTC](https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451/1 "2020-05-28T18:49:54Z")

</div>

hello,

I am trying to build a chart with some data from mysql database.  
I have a query to the database and it returns a object with temperatures that I want to send to a chart and make a line chart. So that I can see the change of temperature through the last 30 days.

This is the output of the query:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc64c37d54a8224b81f613a65dbce77a77e88530.png)

I receive the month and the respective average temperature. Ou is it possible to put it in a line chart?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 May 2020 20:43 UTC](https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451/2 "2020-05-28T20:43:45Z")

</div>

It should certainly be possible. The help info in the ui\_chart node signposts you to the correct data formatting. I don't use it often enough to remember off the top of my head.

The UI charts, at least the line chart, generally anticipates that the X axis will be JavaScript date/time values I think? So you may have to pass an additional parameter to change to your simple month number - though don't take that as gospel, again the help info should give you the right format.

---

<div class="post-metadata">

**Author:** ![cinhcet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cinhcet/32/438_2.png) [@cinhcet](https://discourse.nodered.org/u/cinhcet)\
**Post date:** [28 May 2020 20:50 UTC](https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451/3 "2020-05-28T20:50:15Z")

</div>

Have a look at

> <https://github.com/node-red/node-red-dashboard/blob/master/Charts.md#line-charts-1>

  
as a start.  
How do you want your x-axis labels to be? You might want to convert `the_month` to a timestamp?

---

<div class="post-metadata">

**Author:** ![node96](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@node96](https://discourse.nodered.org/u/node96)\
**Post date:** [28 May 2020 20:53 UTC](https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451/4 "2020-05-28T20:53:22Z")

</div>

@cinhcet The x-axis should have the months number and the y-axis should have temperature values.

---

<div class="post-metadata">

**Author:** ![node96](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@node96](https://discourse.nodered.org/u/node96)\
**Post date:** [29 May 2020 17:01 UTC](https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451/5 "2020-05-29T17:01:13Z")

</div>

I am trying to do as the example in end of that github page you sent but no luck yet:

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

in the x axis theres some timestamp, and I wanted the month and in the y axis I don't know where it is found. I found that guide not very well explained, could have at least a graphical example.

But that is the chart I am getting and the flow is this:

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

I know it is confusing but, I used those change flows to get the average from the object, there's the average of each month and then join them in an array that I use in the function and send to the chart

The label and topic flows I got from the example, but I don't understand how they work.

The data function as the following code:

```auto
var m={
    "series":["X"],
    "data": msg.payload,
    "labels":["Jul","Aug","Sept", "Oct", "Nov"]
};
return {payload:[m]};

```

---

<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:** [28 July 2020 17:01 UTC](https://discourse.nodered.org/t/build-charts-with-data-from-mysql-database/27451/6 "2020-07-28T17:01:17Z")

</div>

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