Data in dashboard graph

200 views
Skip to first unread message

Sjoerd van Staveren

unread,
Jul 23, 2017, 1:16:11 PM7/23/17
to Node-RED
Hello,

I'm trying to feed the dashboard graph (node-red-dashboard v2.4.3) with data from a MongoDB collection. The payload I retrieve form the database contains a date and a temperature as shown below:

Temperatuur : msg : Object
object
_msgid: "1106c3e6.ccc87c"
topic: "Temperatuur"
payload: array[3]
0: object
datum: "Sun, 23 Jul 2017 18:30:14 +0200"
temperatuur: 17.4
1: object
datum: "Sun, 23 Jul 2017 18:40:12 +0200"
temperatuur: 17.6
2: object
datum: "Sun, 23 Jul 2017 18:51:57 +0200"
temperatuur: 17.7



When I feed the Chart node with this payload I do not see anything in the graph so I suppose I'm using the wrong format for these data. What should the format be so that I get a graph with the date on the X-axis and the temperature on the Y-axis?

Regards,

Sjoerd

Sjoerd van Staveren

unread,
Jul 25, 2017, 5:48:13 AM7/25/17
to Node-RED
I solved it myself. The format in which the data should be fed into the chart node is:

msg.payload : array[1]
array[1]
0: object
key: "Temperatuur"
values: array[114]
[0 9]
0: array[2]
0: "2017-07-24T14:51:42.000Z"
1: 19.5
1: array[2]
0: "2017-07-24T15:01:33.000Z"
1: 19.8
2: array[2]
3: array[2]
4: array[2]
5: array[2]
6: array[2]
7: array[2]
8: array[2]
9: array[2]

The script I used the do this is:

Geef de code hier op...var newPayload = [];

for ( var i=0; i<msg.payload.length; i++) {
        newPayload[i] = [];
        for ( var j=0; j<2; j++) {
                newPayload[i][0] = (msg.payload[i].time),
                newPayload[i][1] = (msg.payload[i].data.current_observation.temp_c)
        }
}
    
msg.payload = [{key: "Temperatuur", values: newPayload}];
return msg;


The result is a graph with the historical data:












I hope this will help some others in this group. 

Regards,

Sjoerd
Reply all
Reply to author
Forward
0 new messages