Accessing varying array object for input to node chart

Hi

Being returned from a HTTP weather API inquiry, the payload I receive is an array that can have a varying number of elements (I think it can vary from 5 to 288). I can feed a single element into a chart node but am struggling to come up with a way of looping through the elements until the end and feeding the associated entries into the chart node (one at a time).

(Okay - goddamit - I'm a newbie - didn't want to mention it, but I suppose it is self evident - but I just love Node-Red. Background info - Node-Red running on a Raspberry Pi using MQTT to communicate via long range WiFi to various Arduino (MKR1010s) remote solar powered boards.) Thanks for any assistance!

Picture: referencing a single array object:

Hello Alan,

it doesnt have to be "one at a time" .. you could structure the chart data as described in this article and send all the values for x and y axis at once in a single msg.

Or if you use a Change node to Move msg.payload.observations To msg.payload then you will have the array in msg.payload, then you can feed it through a Split node and it will give you a stream of separate messages which you can process and send to the chart node.

It is more efficient to reformat the whole message and send it in one go, but possibly easier to send them one at a time.

1 Like

Thank you so much UnborN and Colin.

Got lost with UnborN’s suggestion so tried Colin’s. Worked a treat and using a split node to a debug node I could ‘see’ all the elements ready for the ‘y’ axis of my chart. You bewdy!

Only when I sent it to a chart node I got strange results as I hadn’t handled the x axis correctly (ie not at all :grinning:). All the elements came through pretty well simultaneously and my line graph had 2 or 3 x axis entries.

I’m sooooo close and feel a combo of both suggestions will give me a solution but it’s a little (read a lot) out of my current capability.

But persevere I will … thanks again.

Exactly .. thats the problem of sending the values as multiple msgs with the y-axis value as a msg.payload.
The x-axis will be the timestamp when the msg arrives? and its not what you want in this case

Paste here a sample of your data (not a screenshot) and tell us what fields of the msg you want as y-axis and what for x-axis .. so we can try to help and create a chart example.

ps. When you hover over the msg.payload, in the Debug window, a copy value icon will appear so you can easily copy the msg.

UnborN, thanks to your first reference article, I discovered you could provide a chart with a msg.timestamp value; so … I managed (eventually after much experimentation) to split node (NB using split node as a verb!) a date/time array field alongside my other msg,payload array field as input to a chart, and bingo! She’s a goer. Phew!

Love the journey - so far to go but loads of fun. Especially with the amazingly generous assistance from forums.

Thanks again. I’ll be back.

2 Likes

Addendum (the boring story goes on - and on - and on):

I set up a function as per the article first mentioned (after a UTube video and much mucking around) to manage to have two feeds into the chart. Brilliant.

My learning curve goes on … next stepper motor control! Ha! Now exactly where to begin …

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