Normally I'd reply with a bit of Jsonata that results in the same output... but lately I've been converting my code to a more "functional" style, to minimize looping and global function variables...
So if you will allow me try my hand at some javascript using array mappings instead:
// Extract rain data from API
let rain = msg.payload.map( data => {
return {
x: data.observation_time.value,
y: data.precipitation.value.toFixed(1)
};
});
// Extract temperature data from API
let temp = msg.payload.map( data => {
return {
x: data.observation_time.value,
y: data.temp.value.toFixed(1)
};
});
//Build chart Structure
msg.payload = [
{
series: [ "Rain", "Temp" ],
data: [ rain, temp ]
}
];
return msg;