How do i do that ? i searched the forum and there was a suggestion to use map function in function node, but there was no clear instructions, i don't know javascript so please someone can help me....
i want to feed the output to a timeplot graph in flexdash, and i think it requires the format to be in
below format, i am not sure what this format is, since i dont speak this 'language'
Try setting msg.labels to JSONata J: [$$.payload.R]
and then msg.payload to JSONata J: [[$$.payload.D]] or [$$.payload.D.[$]] in a change node.
You have to set msg.labels first, as if you set payload the data will be overwrtten.
Since I am also a bit uncertain how to use map() I've written a function using your data to explain it to myself. It creates arrays and for comparison, an object. I hope it's useful.
const source=[{ "R": "Batch Preparation Delay", "D": 281 }, { "R": "Tea - Lunch Break", "D": 109 }, { "R": "Laminate Loading", "D": 58 }]
// The map() function calls another function for each element of an array.
// It returns another array
// Two different ways to use map() to transform the input array
// Firstly Define a function to return one array element D value
function getDValues(element) {
return element.D
}
// Call that function for each array element
const Darr = source.map(getDValues)
//Exactly the same thing for R values but expressed more compactly
const Rarr = source.map(e => { return e.R })
// The compact form for D values
//const Darr = source.map(e => { return e.D })
// to create an array of objects
const Robj = source.map(e => { return { R: e.R } })
msg.payload = {R:Rarr, D:Darr, Robj: Robj}
return msg;
ps You can always rely on @E1cid to provide a Jsonata answer, sadly I can never grasp why it works!
Perfect !. I got the required format. now I will feed that into the chart and see, how it works.
I also got the same result by modifying my mysql query, got two separate queries to output the results into two different arrays and then merged them with a join node, and got the same result as your method
Will give this a try @E1cid 's solution worked for me. and i also got a workaround by having two separate queries and then merging them with join node. (not a neat solution, but works)