Cant display data in the chart node

Humidity and temperature data isnt being shown on chart node it remains blank
i am using this set up on local node red (PC)

with the code inside function node as follows

// Array of simulated temperatures
var temp1 = [15, 17, 18.5, 20, 21.5, 23, 24, 22.2, 19, 1];

// Array of simulated relative humidities
var humidity1 = [50, 55, 61, 68, 65, 60, 80, 70, 62, 53];

var counter1 = context.get('counter1') || 0;
counter1 = counter1 + 1;
if (counter1 > 9)
    counter1 = 0;
context.set('counter1', counter1);

msg = {
        d: {
            "temperature": temp1[counter1],
            "humidity": humidity1[counter1]
return msg;

This iss the Cloud application that receives messages from the simulated device (PC)


so where/when does counter1 get incremented?

I can't see how that happens. But I'm stupid. (Ask anyone here)

Also, with the second picture where you have the ibmiot node and a debug node.

It may help if you show what the message is/contains.

Hi @rahim100 , and welcome to our community!! Could you share your debug sidebar, for check if the data is reciving!!

Also i can see that the IBM event node is disable, i don't know if your data is from here!!

i used you example to try, i share!!
To display two or more data in the chart node, you might set a different topic for each payload, i add two change nodes to get the payload (Humidity and Temperature) and also in the same set the topic for each:

Captura de pantalla 2021-07-15 a la(s) 7.14.40 p. m.

Captura de pantalla 2021-07-15 a la(s) 7.14.50 p. m.

Captura de pantalla 2021-07-15 a la(s) 7.15.17 p. m.


[{"id":"dc9f78188b297168","type":"tab","label":"Flow 10","disabled":false,"info":""},{"id":"7af556e468b9d410","type":"function","z":"dc9f78188b297168","name":"","func":"// Array of simulated temperatures\nvar temp1 = [15, 17, 18.5, 20, 21.5, 23, 24, 22.2, 19, 1];\n\n// Array of simulated relative humidities\nvar humidity1 = [50, 55, 61, 68, 65, 60, 80, 70, 62, 53];\n\nvar counter1 = context.get('counter1') || 0;\ncounter1 = counter1 + 1;\nif (counter1 > 9)\n    counter1 = 0;\ncontext.set('counter1', counter1);\n\nmsg = {\n    payload:\n    {\n        d: {\n            \"temperature\": temp1[counter1],\n            \"humidity\": humidity1[counter1]\n        }\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":260,"wires":[["16f7758adbc438de","21901993a1fbe778","77212912fd1db75a"]]},{"id":"96f826fccb4ab9bc","type":"inject","z":"dc9f78188b297168","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":260,"wires":[["7af556e468b9d410"]]},{"id":"16f7758adbc438de","type":"debug","z":"dc9f78188b297168","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":220,"wires":[]},{"id":"9c57e37be2f1561d","type":"ui_chart","z":"dc9f78188b297168","name":"","group":"ec90e75fa51bd4b5","order":0,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","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,"x":730,"y":260,"wires":[[]]},{"id":"21901993a1fbe778","type":"change","z":"dc9f78188b297168","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.d.temperature","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"temperature","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":260,"wires":[["9c57e37be2f1561d"]]},{"id":"77212912fd1db75a","type":"change","z":"dc9f78188b297168","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.d.humidity","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"humidity","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":300,"wires":[["9c57e37be2f1561d"]]},{"id":"ec90e75fa51bd4b5","type":"ui_group","name":"Group 1","tab":"f6fbed9ae361a67c","order":1,"disp":true,"width":6},{"id":"f6fbed9ae361a67c","type":"ui_tab","name":"Tab 11","icon":"dashboard","order":11}]

In the Dashboard i can see:

Captura de pantalla 2021-07-15 a la(s) 7.15.09 p. m.

I hope it helps you

Should be here... but my JS is weak.

Hopefully I am not adding my name to the dunce cap :stuck_out_tongue: But what I don't see is what makes the loop work.. or is that done by the inject node? But wouldn't the counter just start over at 0 each time then?

Yeah the code is executed when i inject it :grin: don't worry I'm a noob as well

here you go
ibmiot node is recieving data from the flows on PC via Watson Iot

i have enabled it now and the data is being sent from the flows in the First picture with inject node and device payload which is on my pc so the cloud application on picture 2 is recieving the humidity and temperature data but i want to display them on a chart on the cloud application i created

You are using Windows, so try the Snipping Tool app (type snipping tool in the Windows search bar) so we don't have to squint at the relevant data amongst the whole desktop.

thanks for the reply and where do i put the json code in sorry i am new to this is it inside the function node?

I see the +1 outside the loop.

But if it works, who am I to argue?

Is there a loop - look again :wink:

I think the loopiness is done by clicky-injecty mode...

Ah, yeah.

So why do it at all?

Just send the data in as it arrives.....

Anyway, thanks.

I'm not the brightest. :wink:

Hi @rahim100 . Again to display your data on a chart, you only need add a specific topic for each payload. You can import and export your project, i recommend you read all the official Node-RED documentation, here explain how to import a project, use it to import the JSON that i shared you.

Why are you doing that at all?

You could just send the data to the chart node - with different topics - and it would display.

Putting it into an array seems like making work for no reason.

Well the thing is the loop is for a condition which will send the message to either to the device itself or the slack when a certain temperature or humidity is reached but before that i wanted to show the data on a chart.

Exactly what data are you sending to the chart node?
Use a debug node and copy the value of msg.payload
Untitled 3

How do you label the humidity and temp on the chart ?

With the msg.topic:
change node 1 -> msg.topic -> Humidity
change node 2 -> msg.topic -> Temperature


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