I have a Node-RED flow that uses an API request for my cycle routes. It returns a huge array up to 2000 points each for elevation, speed & grade. I would like to pull these values out and plot them onto a ride graph. Is there a way of being able to do this with a loop function as the amount will differ per trip and I don’t fancy having to pull each one out individually.
Example
Path for first elevation payload.trip.track_points[0].e
Ah, OK...didn't get that while browsing from my mobile
I tried and quickly modify an example I use for another case, that might work for you.
At least it should give you some hints on how this might work.
Maybe @Paul-Reed is able to comment or improve, as I am not a JS guy
let array = msg.payload.trip.track_points;
var time=0;
var elevation=0;
var speed=0;
var grade=0;
var i=0;
var chartarray = [[]];
for(let i = 0; i < array.length; i++) {
time = array[i].t;
elevation = array[i].e;
speed = array[i].x;
grade = array[i].y;
chartarray[0][i] = {"x":time,"y":elevation};
chartarray[1][i] = {"x":time,"y":speed};
chartarray[2][i] = {"x":time,"y":grade};
}
var chart = [{
"series":["Elevation", "Speed", "Grade"],
"data":chartarray,
"labels":[""]
}];
msg.payload = chart;
msg.topic = "trip"
return msg;