Read a variable in an array of object without variable name

Yes. You can populate the graph one of two ways. You can send an array of data points and the graph will fill itself with those. Or you can send individual points one at a time, and the graph will fill itself with those. You can use either method. In the method I showed, I'm sending individual data points, which eliminates the need for making an array to send at the end. If you want to use that method, then all you need to do is put a return null; at the end of the function. If you want to return a full array, then all you really need to do is create an array and then push the object into it, something like this:

var myKeys = Object.keys(msg.payload[0]);
delete myKeys[0];
var arrToSend = [];
for(let x of msg.payload){
    for(let y of myKeys){
        arrToSend.push({topic:y, payload:x[y], timestamp:x.Tijdstip});
    }
}

Then you just return your array. Either way will work. It's up to you on which method you choose.

1 Like

Hello Madhouse,

Sorry I don't get it. The graph isn't showing something, and the PLC is overloaded with all the data he is writing when I want to show my graph.

This comes from the debug node:
image

And the file is like this:

Previous I have made an array with series + data + labels and for every series I made an array of value and time:
image

As you told with sending every single data to the graph looks for me easier but I don't know how to do it.

Thanks in advance.

Interesting. From your debug, it looks like you're getting an every other message pattern. It also looks like your debug node is only configured to show msg.payload instead of the complete msg object. You'll want to change it to that so you can see the whole object coming through. The other thing you can do is to send out a copy of msg.payload and a copy of myKeys before it processes them. If you're using the code example I posted above, put this line after delete myKeys[]0];.

node.send({"myKeys":myKeys, "data":msg.payload});

This will pop out myKeys and msg.payload the the debug node so we can identify where it might be capturing the erroneous entries. Let me know what comes across on the debug and we'll be able to figure it out from there.

Hello Madhouse,

With the debug node only msg object I have received the following:

It looks I have an series(topic), x-axis (timestamp) and Y-axis (payload)

With sending only myKeys and the payload we will get the following:

Is it possible that the graph can't recognize a null as series/topic?

I have tried the following to remove the null of the array:


var myKeys = Object.keys(msg.payload[0]);
myKeys.shift();
//delete myKeys[0];
node.send({"myKeys":myKeys, "data":msg.payload});
var arrToSend = [];
for(let x of msg.payload){
    for(let y of myKeys){
        node.send({topic:y, timestamp:x.Tijdstip, payload:x[y]});
    }
}


return null

And now I get the data I want to see on the graph only the graph doesn't show anything.

What kind of charting library are you using ? The timestamps are "unusual" for charting libraries, usually they require a unix timestamp or ISO 8601.

Hello bakman2,

You have set me to check the right timestamp and yes it was the wrong one.

Now I use the ISO8601 time and the data is showing in the graph:

Only I have still one question. The time that is saved in the CSV file is from 10:50 and with the debug node I see that the flow is sending also 10:50 but the graph transfer the data to 11:50. How can I change that to the right time?

What format do the timestamps show now ? If the ISO8601 timestamp includes a 'Z', with the offset after that, or if there is no offset, it will assume UTC. You can add -1 after the Z to force the offset.

The format is : 2022-12-19T11:34:21.791Z

I have found the fault in my flow:

The inject node gives the UTC time 10:35 I change that with the Date/Time formatter node to 11:35 because the time in the CSV is correct with our local time.

When I ask for a graph the flow get the data from the CSV node and get 11:35 ("Z") and gives it trough to the graph node, and the graph node change the UTC time to the local time with +1 hour and then I see 12:35 on the graph.

I think the best solution for me: Not using the Date/Time formatter node and work only with UTC time, and the graph node transfers it to the right local time.

Absolutely that is the best way. Use UTC everywhere except where you need to display it.

Glad we got that working! Time displays can be such finicky things. But at least you can use the graph for what it's worth and get the data out now.

The only thing I have to do now is filtering the right time.

I have added an If statement with for filtering and I would like to use two timepicker in my dashboard.

How can I easily convert the picked time to the right format like the format in the CSV file?

Most things that allow for time selection in Node-Red will utilize the standard format. When you select a time, the node will pass out the ISO time format that you're currently using, so you should just be able to add an if statement where the time to be checked is greater than the start time variable and less than the end time variable.

Hello Madhouse and bakman2,

Everything works and I am happy that it work as I was hoping for.

Without your help it was not possible.

Showing the right data and filtering the correct time is finished and it work for me good enough.

Many thanks!

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