# Accessing varying array object for input to node chart

**URL:** <https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815>\
**Category:** Dashboard\
**Tags:** uibuilder\
**Created:** [7 December 2021 07:40 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815 "2021-12-07T07:40:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alpal](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alpal/32/60536_2.png) [@Alpal](https://discourse.nodered.org/u/Alpal)\
**Post date:** [7 December 2021 07:40 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/1 "2021-12-07T07:40:03Z")

</div>

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:

 ![XXX](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e407cb2a48e34a9839dec621dd1603b96558cec4.jpeg)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [7 December 2021 07:50 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/2 "2021-12-07T07:50:28Z")

</div>

> [@Alpal](#):
>
> looping through the elements until the end and feeding the associated entries into the chart node (one at a time)

Hello Alan,

it doesnt have to be "one at a time" .. you could structure the chart data as described in this [article](https://github.com/node-red/node-red-dashboard/blob/master/Charts.md#stored-data) and send all the values for x and y axis at once in a single msg.

---

<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:** [7 December 2021 08:10 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/3 "2021-12-07T08:10:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alpal](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alpal/32/60536_2.png) [@Alpal](https://discourse.nodered.org/u/Alpal)\
**Post date:** [8 December 2021 05:08 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/4 "2021-12-08T05:08:35Z")

</div>

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 😀). 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.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 December 2021 09:27 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/5 "2021-12-08T09:27:23Z")

</div>

> [@Alpal](#):
>
> Only when I sent it to a chart node I got strange results as I hadn’t handled the x axis correctly

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.

---

<div class="post-metadata">

**Author:** ![Alpal](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alpal/32/60536_2.png) [@Alpal](https://discourse.nodered.org/u/Alpal)\
**Post date:** [8 December 2021 09:54 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/6 "2021-12-08T09:54:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alpal](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alpal/32/60536_2.png) [@Alpal](https://discourse.nodered.org/u/Alpal)\
**Post date:** [9 December 2021 06:22 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/7 "2021-12-09T06:22:14Z")

</div>

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 …

---

<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:** [25 December 2021 11:35 UTC](https://discourse.nodered.org/t/accessing-varying-array-object-for-input-to-node-chart/54815/8 "2021-12-25T11:35:21Z")

</div>

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