Firstly, to everyone for all your hard work and help Secondly, I could really do with some help here! I am trying to build a function which will render the output needed to feed stored data into line charts as detailed here: https://github.com/node-red/node-red-dashboard/blob/master/Charts.md
Env:
I am calling data in from Firebase Realtime DB using the node-red-contrib-firebase module - which is working fine.
Msg payload format
Data objects are being pulled in from Firebase and the incoming msg.payload looks like this:
msg.payload = {
"-LcgJ2ryhWC4d7tVOX1X": {
"score": "1",
"ts": "1555521617.281100",
},
"-LcgJ2sr0o9mu26pEKUn": {
"score": "2",
"ts": "1555521617.281200",
}
}
What am I trying to do?
I am trying to build a function to feed historical data into a chart.
The idea being to insert data into the appropriate x and y arrays within the data property of the data property of the historicalData object as shown below.
...
"data":[
[{ "x": ts[key0], "y": score[key0] }],
[{ "x": ts[key1], "y": score[key1] }
] //etc...iterating through msg object
],
...
I believe this then needs to be passed into the output array.
Current code attempt
var output = [];
var historicalData = {
"series":["Sentiment"],
"data":[[{}]], //Several hundred x,y items from DB added here
"labels":[""]
};
for (i = 0; i < Object.keys(msg.payload).length; i++){
var key = Object.keys(msg.payload)[i];
var ts = msg.payload[key].ts;
var score= msg.payload[key].score;
if (score){
historicalData.data.x = ts;
historicalData.data.y = tx;
}
}
Can anyone please help me figure this out! I have spent almost 20 hours today revising object constructions, iterations, spreads, and the rest trying to solve this without asking anyone else for their time...so believe me, I have tried to look this one up and I still can't for the life of me find a sensible way to do this object updating.
Any help would be much appreciated!
Best wishes
Dan