Hi!
Im a beginner and still learning NodeRed.
I have browsed through the forums to try to find information.
However Im stuck.
I have a table in the database that I want to pull some data from.
each line from the database query looks like this:
time: "2022-09-20T07:58:55.000Z"
outdoortemperature: 13
loggedoutdoortemp: 10
What I want the line chart to show
is how the two temperatures change and corelate over time.
I have created a change node with a J:expression (found that in a tutorial)
This is my J:expression code:
[{"series" : [$distinct(time)],
"data":$each(payload{time:loggedoutdoortemp},function($val){$val})
}]
I know it probably doesnt make any sense at all but this is the closest I got to something that looks like what I understood is needed in the spec.
However, when I use this in nodered Im getting a
""Invalid JSONata expression: Key in object structure must evaluate to a string; got: "2022-09-20T07:58:55.000Z"" error message.
And now Im completely stuck.
Any ideas how to get forward?
Thanks for all help and sorry if my post is messy.
/N
You could probably adapt this dynamic routine with little ease...
So, i am not 100% certain what you are after but if (by the title "dynamic series") you mean sending alternative types of data from a database (i.e. varying fields and varying quantities) then this should get you close.
It was a simple adaption of the previous solution I pointed you to, modified to build the series from the field names of the 1st data element in the data passed in.
There are 2 injects to simulate two different sets of mySQL data
[image]
[i1GL9BSOWR]
[{"id":"227e8b13.87c804…
1 Like
[{
"series": [""],
"labels": [""],
"data": [[payload.{
"x": datetime,
"y": $."m"
}]]
}]
this works for me.
smanjunath211:
this works for me.
Hi, yeah, that gave me a list of the timestamps.
Not sure I follow "where" to add the rest of the data though (temperatures)
I take it you want to plot two lines, outdoor and logged?
If so then the jsonata would be
(
$lines := ["outdoortemperature","loggedoutdoortemp"];
[
{
"series": $lines,
"data":[
$lines.[($key := $;
$$.payload.{"x": $.time, "y": $lookup($, $key)}
)]
],
"labels":[]
}
]
)
2 Likes
YES! Fantastic!
Thank you very much, worked like a charm!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.