Searching values in an object

Hi folks,
i am looking for help. Maybe one can help me.
I am requesting data from a public api.
i read out data on an daily basis and want to plot it in a dashboard 2.0 chart in node-red.
The returned data is a json object as you see below.
so far i didn't find the solution to get this working.

Does anyone have an idea?

Thanks for your help

{"jsonData":{"request":{"component":"1","scope":"2","station":"286","date_from":"2025-01-11","date_to":"2025-01-11","time_from":"01:00:00","time_to":"24:00:00","index":"id","lang":"en","datetime_from":"2025-01-11 00:00:00","datetime_to":"2025-01-11 23:00:00"},"indices":{"data":{"station id":{"date start":["0: Id of component - integer","1: Id of scope - integer","2: Value - number","3: Date of measure end - string","4: Index - string|null"]}}},"data":{"286":{"2025-01-11 00:00:00":[1,2,5,"2025-01-11 01:00:00",null],"2025-01-11 01:00:00":[1,2,5,"2025-01-11 02:00:00",null],"2025-01-11 02:00:00":[1,2,8,"2025-01-11 03:00:00",null],"2025-01-11 03:00:00":[1,2,8,"2025-01-11 04:00:00",null],"2025-01-11 04:00:00":[1,2,7,"2025-01-11 05:00:00",null],"2025-01-11 05:00:00":[1,2,5,"2025-01-11 06:00:00",null],"2025-01-11 06:00:00":[1,2,6,"2025-01-11 07:00:00",null],"2025-01-11 07:00:00":[1,2,7,"2025-01-11 08:00:00",null],"2025-01-11 08:00:00":[1,2,9,"2025-01-11 09:00:00",null],"2025-01-11 09:00:00":[1,2,7,"2025-01-11 10:00:00",null],"2025-01-11 10:00:00":[1,2,9,"2025-01-11 11:00:00",null],"2025-01-11 11:00:00":[1,2,10,"2025-01-11 12:00:00",null],"2025-01-11 12:00:00":[1,2,16,"2025-01-11 13:00:00",null],"2025-01-11 13:00:00":[1,2,17,"2025-01-11 14:00:00",null],"2025-01-11 14:00:00":[1,2,15,"2025-01-11 15:00:00",null],"2025-01-11 15:00:00":[1,2,16,"2025-01-11 16:00:00",null],"2025-01-11 16:00:00":[1,2,18,"2025-01-11 17:00:00",null],"2025-01-11 17:00:00":[1,2,17,"2025-01-11 18:00:00",null],"2025-01-11 18:00:00":[1,2,16,"2025-01-11 19:00:00",null],"2025-01-11 19:00:00":[1,2,17,"2025-01-11 20:00:00",null]}}}}

I created a code to read out the data in need to go on

var inputData = msg.payload;
var result = [];

const stationData = inputData ["jsonData"]["data"]["286"];

for (const dateStart in stationData) {
  const value = stationData[dateStart][2]; // Index 2 enthält den Value
  result.push({ x: dateStart, y: value });
}

var msg = {
  payload: result
};

return msg;

Using this code i get the object

[{"x":"2025-01-12 00:00:00","y":27},{"x":"2025-01-12 01:00:00","y":19},{"x":"2025-01-12 02:00:00","y":14},{"x":"2025-01-12 03:00:00","y":10},{"x":"2025-01-12 04:00:00","y":10},{"x":"2025-01-12 05:00:00","y":11},{"x":"2025-01-12 06:00:00","y":10},{"x":"2025-01-12 07:00:00","y":8},{"x":"2025-01-12 08:00:00","y":9}]

Putting this in the dashbnorad 2.0 chart node doesnt plot the graph.
I adjusted the chart node as follows:
Series : None
Y Key: y
X: Key: x

I do not have a clue what i am doing wrong.

The timestamp can (apparently) not be parsed by the chart node.

If you change the function to something like:


const input = msg.payload.jsonData.data['286']
msg.payload = Object.values(input).map(d=>{return {x:new Date(d[3]),y:d[2]}})
return msg;

It will return dates that it can parse:

Not entirely sure if this will be 100% correct, or that the chart node requires an actual timestamp, perhaps this should be clarified in the documentation, ie 'what is a timestamp' or valid timeformat for the input @joepavitt ?

Yeah, we should in theory support the string as it is a valid timestamp - can you raise an issue please?

We should be able to check if the value is already a Date object, and if not, and the chart is set to be a "Timeseries" x-axis, then we just try to parse whatever we're given

Thanks you for your reply. It works well.

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