# Doubt with data from Mysql A NodeRed and graph it

**URL:** <https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256>\
**Category:** General\
**Tags:** node-red-dashboard, database, chart, mysql\
**Created:** [15 April 2024 18:35 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256 "2024-04-15T18:35:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![LilGrundy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lilgrundy/32/87875_2.png) [@LilGrundy](https://discourse.nodered.org/u/LilGrundy)\
**Post date:** [15 April 2024 18:35 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/1 "2024-04-15T18:35:08Z")

</div>

Good day colleagues, I have a question, it turns out that I am trying to extract data from the MySql table, and make a push to graph it in a chart, all with a date range, it turns out that it does not give any error somewhere in the code but at the same time See my chart, it is not graphing anything, neither the numbers nor the dates of said numbers appear, any ideas?

This is my flow, which in itself is a sketch so far, since in the future I want to make a type of data history in which when I indicate the date of the database I graph it in different graphs.

```auto
[
    {
        "id": "c7d50494.9de1e8",
        "type": "mysql",
        "z": "c30fd861d10ee860",
        "mydb": "fb05e811b8b0da75",
        "name": "MySQL",
        "x": 600,
        "y": 240,
        "wires": [
            [
                "c4301fb0.4a0ef",
                "4282d2f5564a14d7"
            ]
        ]
    },
    {
        "id": "c4301fb0.4a0ef",
        "type": "function",
        "z": "c30fd861d10ee860",
        "name": "Format Data",
        "func": "var data = msg.payload;\nvar formattedData = {\n labels: [],\n series: [[]]\n};\n\nfor (var i = 0; i < data.length; i++) {\n formattedData.labels.push(data[i].fecha); \n formattedData.series[0].push(data[i].energiatotal); \n}\n\nmsg.payload = formattedData;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 810,
        "y": 240,
        "wires": [
            [
                "c50a25d2.69bf68",
                "a7c5384798c93fba"
            ]
        ]
    },
    {
        "id": "c50a25d2.69bf68",
        "type": "ui_chart",
        "z": "c30fd861d10ee860",
        "name": "",
        "group": "f1a48b30.40c82",
        "order": 0,
        "width": "12",
        "height": "6",
        "label": "Chart",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "No data available",
        "dot": false,
        "ymin": "0",
        "ymax": "100",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1020,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "81c32302a70e46c6",
        "type": "inject",
        "z": "c30fd861d10ee860",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 240,
        "wires": [
            [
                "178b787c08847eb3"
            ]
        ]
    },
    {
        "id": "178b787c08847eb3",
        "type": "function",
        "z": "c30fd861d10ee860",
        "name": "function 217",
        "func": "msg.topic = \"SELECT fecha, energiatotal FROM totales WHERE fecha BETWEEN '2023-10-26 00:00:00' AND '2023-10-26 23:59:59'; \" ;\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 240,
        "wires": [
            [
                "c7d50494.9de1e8"
            ]
        ]
    },
    {
        "id": "4282d2f5564a14d7",
        "type": "debug",
        "z": "c30fd861d10ee860",
        "name": "debug 42",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 800,
        "y": 320,
        "wires": []
    },
    {
        "id": "a7c5384798c93fba",
        "type": "debug",
        "z": "c30fd861d10ee860",
        "name": "debug 43",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 800,
        "y": 160,
        "wires": []
    },
    {
        "id": "fb05e811b8b0da75",
        "type": "MySQLdatabase",
        "name": "",
        "host": "127.0.0.1",
        "port": "3306",
        "db": "plc",
        "tz": "",
        "charset": "UTF8"
    },
    {
        "id": "f1a48b30.40c82",
        "type": "ui_group",
        "name": "Histo",
        "tab": "34f7d76f.774d7e",
        "order": 1,
        "disp": true,
        "width": "12",
        "collapse": false,
        "className": ""
    },
    {
        "id": "34f7d76f.774d7e",
        "type": "ui_tab",
        "name": "PROTOTIPO",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

```

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 April 2024 18:47 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/2 "2024-04-15T18:47:43Z")

</div>

I'm not at a computer to load your flow but it looks like you haven't provided any sample data anyway (which makes it difficult for anyone to help you) but here is a universal flow that might help: [Dynamic series identification from message, send data to Chart - #5 by Steve-Mcl](https://discourse.nodered.org/t/dynamic-series-identification-from-message-send-data-to-chart/36682/5)

---

<div class="post-metadata">

**Author:** ![LilGrundy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lilgrundy/32/87875_2.png) [@LilGrundy](https://discourse.nodered.org/u/LilGrundy)\
**Post date:** [15 April 2024 18:50 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/3 "2024-04-15T18:50:49Z")

</div>

Thanks, I'm going to read the example topic you sent me and see how I can implement it.

---

<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:** [15 April 2024 20:45 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/4 "2024-04-15T20:45:00Z")

</div>

Although you have debug nodes in your flow you have not shown us what they output, so we are guessing.

However, maybe this post will be helpful:

> [@Convert object from sqlite to use in line graph](https://discourse.nodered.org/t/convert-object-from-sqlite-to-use-in-line-graph/85906/2):
>
> 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 …

---

<div class="post-metadata">

**Author:** ![LilGrundy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lilgrundy/32/87875_2.png) [@LilGrundy](https://discourse.nodered.org/u/LilGrundy)\
**Post date:** [15 April 2024 21:06 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/5 "2024-04-15T21:06:53Z")

</div>

Oh sorry, I didn't realize that I missed adding the debug, these are, debug 43 is the one that I understand does not give the correct format for the chart, I'm still trying to graph my Mysql data in a node chart network, but none of them graph me hehe, it has been something difficult.

 ![debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0fbd75c6a3cb277fc6dacc7bf84ad7ed66e6a32f.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 April 2024 21:14 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/6 "2024-04-15T21:14:36Z")

</div>

If you run your data through the flow I pointed you at you would see the data should be an array of arrays of objects. Yours is an array of objects.

Alternatively, follow the [info in the docs](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md#line-charts-1)

---

<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:** [15 April 2024 21:54 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/7 "2024-04-15T21:54:38Z")

</div>

To add to Steve's comment, msg.payload[0].data should be an array containing an array/s of objects, while you just have an array of objects.

---

<div class="post-metadata">

**Author:** ![LilGrundy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lilgrundy/32/87875_2.png) [@LilGrundy](https://discourse.nodered.org/u/LilGrundy)\
**Post date:** [15 April 2024 21:58 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/8 "2024-04-15T21:58:21Z")

</div>

ooo, that is, it should be a specific json to be able to graph the group of data I want, or am I wrong?

---

<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:** [14 July 2024 21:58 UTC](https://discourse.nodered.org/t/doubt-with-data-from-mysql-a-nodered-and-graph-it/87256/9 "2024-07-14T21:58:26Z")

</div>

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