# Can't get the chart working with dataset

**URL:** <https://discourse.nodered.org/t/cant-get-the-chart-working-with-dataset/93114>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [13 November 2024 10:48 UTC](https://discourse.nodered.org/t/cant-get-the-chart-working-with-dataset/93114 "2024-11-13T10:48:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ektoekto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ektoekto/32/89084_2.png) [@ektoekto](https://discourse.nodered.org/u/ektoekto)\
**Post date:** [13 November 2024 10:48 UTC](https://discourse.nodered.org/t/cant-get-the-chart-working-with-dataset/93114/1 "2024-11-13T10:48:19Z")

</div>

I have next example data:

```auto
let dataArray = [
    {
        name: "room 1",
        tempdata: [
            { time: 1710584361161, temp: 21.1 },
            { time: 1710584371161, temp: 22.0 },
            { time: 1710584381161, temp: 21.5 }
        ]
    },
    {
        name: "room 2",
        tempdata: [
            { time: 1710584361161, temp: 19.2 },
            { time: 1710584371161, temp: 20.3 },
            { time: 1710584381161, temp: 18.9 }
        ]
    }
];

```

And then I use this function to format it:

```auto
let formattedData = dataArray.map(series => {
    return {
        topic: series.name, // Label for the series
        payload: series.tempdata.map(point => ({
            x: new Date(point.time).toISOString(), // Convert to UTC ISO string
            y: point.temp // Temperature as y value
        }))
    };
});

msg.payload = formattedData;

```

So the data I send to the chart looks like this:

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

But the data doesn't get trough. All I see is this:

 ![kuva](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/895108e96ad0756b8d01ebe27420b75edce25330.png)

These are my chart settings:

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

How could one get that example data trough to a chart?

---

<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:** [13 November 2024 11:21 UTC](https://discourse.nodered.org/t/cant-get-the-chart-working-with-dataset/93114/2 "2024-11-13T11:21:57Z")

</div>

The dashboard 2 chart does not need the same `x: .., y: ..` formatted data as dashboard 1.

Instead you should aim for a flatter data structure like this (you see that data for the two lines do not need to be kept separate)

```auto
msg.payload = [
            { name: "room 1", time: 1710584361161, temp: 21.1 },
            { name: "room 2", time: 1710584361161, temp: 19.2 },
            { name: "room 1", time: 1710584371161, temp: 22.0 },
            { name: "room 2", time: 1710584371161, temp: 20.3 },
            { name: "room 1", time: 1710584381161, temp: 21.5 },
            { name: "room 2", time: 1710584381161, temp: 18.9 }
        ]
return msg;

```

If your data was sourced from an SQL database the query might be as simple as  
`SELECT name, time, temp FROM tablename`

And the chart config is like this

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

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

---

<div class="post-metadata">

**Author:** ![ektoekto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ektoekto/32/89084_2.png) [@ektoekto](https://discourse.nodered.org/u/ektoekto)\
**Post date:** [13 November 2024 11:39 UTC](https://discourse.nodered.org/t/cant-get-the-chart-working-with-dataset/93114/3 "2024-11-13T11:39:53Z")

</div>

I made this as my message:

 ![kuva](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/b/5bcc83716af45491e6b72c9e131f704ec5581d62.png)

But it didn't work.

I noticed that you have dropdown buttons here and I don't:

 ![kuva](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e25f2b1444aab0c92782a1e89e4579690c391b1.png)

So I then updated to a newer version. And now I got a lot more options:

 ![kuva](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d77132f851d9d8536294eb550dc422a846a96f43.png)

But still no data:

 ![kuva](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/c/bcfa38c55e960a614b1ec68dc1143eefd8fe8f85.png)

Since it was remembering the Y-scale, I deleted the chart object and made a new one. And now finally I get the data 😃

 ![kuva](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/3183f27c0b27b079b85022fb251eb94d78c13711.png)

So thanks for you repply! I did earlier try this format also but didn't get it to work. The overall issue was that I had some old version.

---

<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:** [13 November 2024 11:45 UTC](https://discourse.nodered.org/t/cant-get-the-chart-working-with-dataset/93114/4 "2024-11-13T11:45:20Z")

</div>

> [@ektoekto](#):
>
> I deleted the chart object and made a new one. And now finally I get the data 😃

Yes, after changing a dashboard widget you have to send an empty array to clear the chart, reload the browser tab, reload it with ctrl f5 or even clear the browser cache.  
I think recent changes have improved the behaviour but it's best always to reload.

---

<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:** [13 December 2024 11:45 UTC](https://discourse.nodered.org/t/cant-get-the-chart-working-with-dataset/93114/5 "2024-12-13T11:45:42Z")

</div>

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