# Issue with Real-Time Data Reading from MQTT Node - Unable to Display Graph

**URL:** https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870
**Category:** Dashboard
**Tags:** node-red-dashboard
**Created:** [28 August 2023 19:15 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870 "2023-08-28T19:15:03Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 19:15 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/1 "2023-08-28T19:15:03Z")

</div>

Hello,

I'm facing a challenge while trying to display a real-time graph based on data retrieved from an MQTT node in Node-RED. My approach involves reading data from the MQTT node and transforming it into the appropriate format. However, despite my efforts, I'm unable to visualize a functional graph. It seems that I might be missing something in my approach.

Here's a snippet of the code I'm currently using in the function node:

 ![Bez tytułu](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4029c6025e3c25c6901f69e85441195bafec2e9.jpeg)

---

<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: [28 August 2023 19:35 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/2 "2023-08-28T19:35:24Z")

</div>

Feed the mqtt node into a debug node and show us what you see in the debug pane.

---

<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: [28 August 2023 19:43 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/3 "2023-08-28T19:43:05Z")

</div>

For real time data you only need to send the y value and maybe a topic to the chart, it will use the current time as x.

eg msg.payload = 42

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 19:48 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/4 "2023-08-28T19:48:02Z")

</div>

![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bb56764d6aebd1338b900c3ed6708d92211ba219.jpeg)

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 19:50 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/5 "2023-08-28T19:50:45Z")

</div>

I'm trying to display both time and measurement data from an MQTT node.

---

<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: [28 August 2023 19:51 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/6 "2023-08-28T19:51:15Z")

</div>

So it's not real time then?

Regardless of that, the format you are trying to assemble with series, data and labels arrays is for stored data and I _believe_ that when you send data in that form, the chart node will redraw with a clean sheet. If there's only one data point you don't get any lines on the chart.

Sorry, multiple edits to adjust what my phone thinks I should be saying.

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 19:59 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/7 "2023-08-28T19:59:38Z")

</div>

> [@jbudd](#):
>
> So it's not real time then?
> 
> Regardless of that, the format you are trying to assemble with series, data and labels arrays is for sure days and I _believe_ that when you send data in that form, the chart node will redraw with a clean sheet. If there's only one data point you don't get any lines on the chart

Experiencing timestamp inaccuracies on Node-RED charts due to a time difference between microcontroller data and the clock of the Raspberry Pi running Node-RED.

My issue revolves around the challenge of displaying the data I receive from an MQTT node at specific time intervals on a chart.

---

<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: [28 August 2023 20:03 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/8 "2023-08-28T20:03:49Z")

</div>

Show us an example set of data points, and what you want the chart to look like.

---

<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: [28 August 2023 20:06 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/9 "2023-08-28T20:06:24Z")

</div>

Probably the stored data format is what you need them, but you need to store the data.

Personally I get data from sensors and store it in a database then at intervals run a query to get the most recent couple of hundred records and feed it to the chart.

No doubt it could be done with context storage too

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 20:08 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/10 "2023-08-28T20:08:35Z")

</div>

![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bb56764d6aebd1338b900c3ed6708d92211ba219.jpeg)  
I provided the dataset above. The data I intend to display consists of timestamps on the X-axis and measurements on the Y-axis. The chart should be a linear graph.

---

<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: [28 August 2023 20:18 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/11 "2023-08-28T20:18:06Z")

</div>

What units are the timestamps in, and how do you know when to drop samples off the front of the chart?

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 20:22 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/12 "2023-08-28T20:22:33Z")

</div>

The time is measured in milliseconds starting from zero, and the data is sent upon pressing a button in the dashboard.

---

<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: [28 August 2023 20:25 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/13 "2023-08-28T20:25:43Z")

</div>

> [@Asiayqyyq](#):
>
> the data is sent upon pressing a button in the dashboard.

Do you mean each sample is sent to MQTT when the button is pressed? Or is a complete sequence sent when the button is pressed?  
If it is a complete sequence then the ideal would be to change the sender so that it sends the whole set as an array instead of a sequence of separate samples.

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 20:27 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/14 "2023-08-28T20:27:14Z")

</div>

> [@Colin](#):
>
> Do you mean each sample is sent to MQTT when the button is pressed? Or is a complete sequence sent when the button is pressed?  
> If it is a complete sequence then the ideal would be to change the sender so that it sends the whole set as an array instead of a sequence of separate samples.

After pressing the button, an entire series of data is sent until the process is stopped

---

<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: [28 August 2023 20:52 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/15 "2023-08-28T20:52:52Z")

</div>

> [@Asiayqyyq](#):
>
> an entire series of data is sent until the process is stopped

Do you mean pressing the button starts it sending, then it keeps sending, every 125 msec, until the process is stopped?

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 20:57 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/16 "2023-08-28T20:57:47Z")

</div>

> [@Colin](#):
>
> Do you mean pressing the button starts it sending, then it keeps sending, every 125 msec, until the process is stopped?

Yes, I have two buttons for triggering data transmission and stopping. Is it possible to achieve this without using a database, directly from the data I currently have?

---

<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: [28 August 2023 21:02 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/17 "2023-08-28T21:02:28Z")

</div>

Do you need the chart to build up as the process runs, or would it be ok to wait till it is all received and then draw it?

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 21:10 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/18 "2023-08-28T21:10:32Z")

</div>

It would be sufficient if the chart was generated after pressing the stop data transmission button.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [28 August 2023 21:11 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/19 "2023-08-28T21:11:57Z")

</div>

I'm not sure what the n in your data is, but if you change the msg (the complete msg, not the msg.payload) to be like

```auto
{topic:"myseries", payload:0.135, timestamp:250}

```

Then it should accept the data and timestamp

---

<div class="post-metadata">

### Author: ![Asiayqyyq](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@Asiayqyyq](https://discourse.nodered.org/u/Asiayqyyq)
#### Post date: [28 August 2023 21:22 UTC](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870/20 "2023-08-28T21:22:51Z")

</div>

I don't quite understand how to do it. Could you elaborate further on how to build the function node?

[Next page](https://discourse.nodered.org/t/issue-with-real-time-data-reading-from-mqtt-node-unable-to-display-graph/80870.md?page=2)
