Hi,
trying to transform an array of JSON-objects for dashboard-chart-node, I have problems with jsonata-code.
Probably it's not hard to solve, thank you for helping!
The third graph ('CALC') is already prepared properly, the two others ('DATEN.humidy' /'DATEN.temperature') don't work.
Underneath input-/output-msg.payload and the jsonata-code for the change-node. The problematic part is written bold, with a comment at the end of the line.
Input msg.payload:
[
{
"DATUM": 1640024797000,
"DATEN": {
"temperature": 14.28,
"humidity": 58
},
"CALC": 29
},
{
"DATUM": 1640024787000,
"DATEN": {
"temperature": 14.33,
"humidity": 59
},
"CALC": 29
},
{
"DATUM": 1640023606000,
"DATEN": {
"temperature": 14.24,
"humidity": 62
},
"CALC": 30
}
]
change node:
set msg.payload to jsonata:
(
$series := [
{ "field_Y": **"DATEN.humidity"**, "field_X": "DATUM", "label": "relative Luftfeuchtigkeit in %", "header": "topic"}, /* "DATEN.temperature" is not correct, how could it be written to properly display the temperature?*/
{ "field_Y": **"DATEN"**, "field_X": "DATUM", "label": "Temperatur in °C", "header": "topic"},
{ "field_Y": "CALC", "field_X": "DATUM", "label": "Enthalpie in kj/kg Luft", "header": "topic"}
];
[
{
"series": $series.label,
"data": $series.[
(
$yaxis := $.field_Y;
$xaxis := $.field_X;
$$.payload.{
"x": $lookup($, $xaxis),
"y": $lookup($, $yaxis)
}
)
]
}
]
)
payload output:
[
{
"series": [
"relative Luftfeuchtigkeit in %",
"Temperatur in °C",
"Enthalpie in kj/kg Luft"
],
"data": [
[
{
"x": 1640024797000
},
{
"x": 1640024787000
},
{
"x": 1640023606000
}
],
[
{
"x": 1640024797000,
"y": {
"temperature": 14.28,
"humidity": 58
}
},
{
"x": 1640024787000,
"y": {
"temperature": 14.33,
"humidity": 59
}
},
{
"x": 1640023606000,
"y": {
"temperature": 14.24,
"humidity": 62
}
}
],
[
{
"x": 1640024797000,
"y": 29
},
{
"x": 1640024787000,
"y": 29
},
{
"x": 1640023606000,
"y": 30
}
]
]
}
]