Multiple chart lines from single array

Hi there, I am losing my mind staring at this one problem and I think I am oh so very close but I just can't crack this nut. I think there is the need for a 'For Loop' within a 'For Loop'. Hopefully you can help!

What I am trying to plot is a join of 4 individual query results (torque) from my influxdb. I have managed to get the results mapped to the point where each tool has an array of x: time and y: torque. All the x values are the same for all tools and is is just the y values that I wish to overlay.

This is an example of the function that I used to map the JSON results from influx to the key:value pairs for plotting

s1 = msg.payload[0].map(obj => {return {x: obj._time, y: obj._value}})
msg.payload = s1;
return msg;

This is the resulting array, post-join, is what I am trying to plot. I have copied and pasted a sample of data. It is an array of 4, where each array has an array of 45 where each object has the x and a y value.

[[{"x":"2022-09-08T15:05:18.000Z","y":0},{"x":"2022-09-08T15:05:19.000Z","y":0},{"x":"2022-09-08T15:05:20.000Z","y":0},{"x":"2022-09-08T15:05:22.000Z","y":0},{"x":"2022-09-08T15:05:23.000Z","y":0},{"x":"2022-09-08T15:05:24.000Z","y":0},{"x":"2022-09-08T15:05:25.000Z","y":0},{"x":"2022-09-08T15:05:27.000Z","y":0},{"x":"2022-09-08T15:05:28.000Z","y":0},{"x":"2022-09-08T15:05:29.000Z","y":0},{"x":"2022-09-08T15:05:31.000Z","y":0},{"x":"2022-09-08T15:05:32.000Z","y":0},{"x":"2022-09-08T15:05:33.000Z","y":0},{"x":"2022-09-08T15:05:34.000Z","y":0},{"x":"2022-09-08T15:05:36.000Z","y":0},{"x":"2022-09-08T15:05:37.000Z","y":0},{"x":"2022-09-08T15:05:38.000Z","y":0},{"x":"2022-09-08T15:05:40.000Z","y":0},{"x":"2022-09-08T15:05:41.000Z","y":0},{"x":"2022-09-08T15:05:42.000Z","y":0},{"x":"2022-09-08T15:05:43.000Z","y":0},{"x":"2022-09-08T15:05:45.000Z","y":0},{"x":"2022-09-08T15:05:46.000Z","y":0},{"x":"2022-09-08T15:05:47.000Z","y":0},{"x":"2022-09-08T15:05:49.000Z","y":0},{"x":"2022-09-08T15:05:50.000Z","y":-0.01},{"x":"2022-09-08T15:05:51.000Z","y":0.027},{"x":"2022-09-08T15:05:53.000Z","y":0.002},{"x":"2022-09-08T15:05:54.000Z","y":0},{"x":"2022-09-08T15:05:56.000Z","y":0},{"x":"2022-09-08T15:05:57.000Z","y":0},{"x":"2022-09-08T15:05:58.000Z","y":0},{"x":"2022-09-08T15:05:59.000Z","y":0},{"x":"2022-09-08T15:06:01.000Z","y":0},{"x":"2022-09-08T15:06:02.000Z","y":0},{"x":"2022-09-08T15:06:03.000Z","y":0},{"x":"2022-09-08T15:06:05.000Z","y":0},{"x":"2022-09-08T15:06:06.000Z","y":0},{"x":"2022-09-08T15:06:07.000Z","y":0},{"x":"2022-09-08T15:06:09.000Z","y":0},{"x":"2022-09-08T15:06:10.000Z","y":0},{"x":"2022-09-08T15:06:11.000Z","y":0},{"x":"2022-09-08T15:06:13.000Z","y":0},{"x":"2022-09-08T15:06:14.000Z","y":0},{"x":"2022-09-08T15:06:16.000Z","y":0}],[{"x":"2022-09-08T15:05:18.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:19.000Z","y":0.068},{"x":"2022-09-08T15:05:20.000Z","y":0.063},{"x":"2022-09-08T15:05:22.000Z","y":0.049},{"x":"2022-09-08T15:05:23.000Z","y":0.068},{"x":"2022-09-08T15:05:24.000Z","y":0.068},{"x":"2022-09-08T15:05:25.000Z","y":0.096},{"x":"2022-09-08T15:05:27.000Z","y":0.068},{"x":"2022-09-08T15:05:28.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:29.000Z","y":0.063},{"x":"2022-09-08T15:05:31.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:32.000Z","y":0.065},{"x":"2022-09-08T15:05:33.000Z","y":0.065},{"x":"2022-09-08T15:05:34.000Z","y":0.065},{"x":"2022-09-08T15:05:36.000Z","y":0.049},{"x":"2022-09-08T15:05:37.000Z","y":0.065},{"x":"2022-09-08T15:05:38.000Z","y":0.065},{"x":"2022-09-08T15:05:40.000Z","y":0.063},{"x":"2022-09-08T15:05:41.000Z","y":0.065},{"x":"2022-09-08T15:05:42.000Z","y":0.068},{"x":"2022-09-08T15:05:43.000Z","y":0.065},{"x":"2022-09-08T15:05:45.000Z","y":0.06},{"x":"2022-09-08T15:05:46.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:47.000Z","y":0.077},{"x":"2022-09-08T15:05:49.000Z","y":0.077},{"x":"2022-09-08T15:05:50.000Z","y":0.053},{"x":"2022-09-08T15:05:51.000Z","y":0.065},{"x":"2022-09-08T15:05:53.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:54.000Z","y":0.049},{"x":"2022-09-08T15:05:56.000Z","y":0.079},{"x":"2022-09-08T15:05:57.000Z","y":0.079},{"x":"2022-09-08T15:05:58.000Z","y":0.049},{"x":"2022-09-08T15:05:59.000Z","y":0.063},{"x":"2022-09-08T15:06:01.000Z","y":0.065},{"x":"2022-09-08T15:06:02.000Z","y":0.065},{"x":"2022-09-08T15:06:03.000Z","y":0.065},{"x":"2022-09-08T15:06:05.000Z","y":0.079},{"x":"2022-09-08T15:06:06.000Z","y":0.075},{"x":"2022-09-08T15:06:07.000Z","y":0.065},{"x":"2022-09-08T15:06:09.000Z","y":0.065},{"x":"2022-09-08T15:06:10.000Z","y":0.046},{"x":"2022-09-08T15:06:11.000Z","y":0.079},{"x":"2022-09-08T15:06:13.000Z","y":0.06},{"x":"2022-09-08T15:06:14.000Z","y":0.063},{"x":"2022-09-08T15:06:16.000Z","y":0.07}],[{"x":"2022-09-08T15:05:18.000Z","y":-5.712},{"x":"2022-09-08T15:05:19.000Z","y":-4.752},{"x":"2022-09-08T15:05:20.000Z","y":-5.159},{"x":"2022-09-08T15:05:22.000Z","y":-4.752},{"x":"2022-09-08T15:05:23.000Z","y":-4.817},{"x":"2022-09-08T15:05:24.000Z","y":-5.179},{"x":"2022-09-08T15:05:25.000Z","y":-4.931},{"x":"2022-09-08T15:05:27.000Z","y":-5.8420000000000005},{"x":"2022-09-08T15:05:28.000Z","y":-5.607},{"x":"2022-09-08T15:05:29.000Z","y":-5.696},{"x":"2022-09-08T15:05:31.000Z","y":-5.224},{"x":"2022-09-08T15:05:32.000Z","y":-4.963},{"x":"2022-09-08T15:05:33.000Z","y":-4.915},{"x":"2022-09-08T15:05:34.000Z","y":-5.484},{"x":"2022-09-08T15:05:36.000Z","y":-5.4030000000000005},{"x":"2022-09-08T15:05:37.000Z","y":-5.8580000000000005},{"x":"2022-09-08T15:05:38.000Z","y":-4.752},{"x":"2022-09-08T15:05:40.000Z","y":-4.296},{"x":"2022-09-08T15:05:41.000Z","y":-6.607},{"x":"2022-09-08T15:05:42.000Z","y":-5.077},{"x":"2022-09-08T15:05:43.000Z","y":-5.452},{"x":"2022-09-08T15:05:45.000Z","y":-5.029},{"x":"2022-09-08T15:05:46.000Z","y":-5.354},{"x":"2022-09-08T15:05:47.000Z","y":-5.549},{"x":"2022-09-08T15:05:49.000Z","y":-5.061},{"x":"2022-09-08T15:05:50.000Z","y":-4.963},{"x":"2022-09-08T15:05:51.000Z","y":-5.94},{"x":"2022-09-08T15:05:53.000Z","y":-5.142},{"x":"2022-09-08T15:05:54.000Z","y":-4.996},{"x":"2022-09-08T15:05:56.000Z","y":-5.37},{"x":"2022-09-08T15:05:57.000Z","y":-5.305},{"x":"2022-09-08T15:05:58.000Z","y":-5.614},{"x":"2022-09-08T15:05:59.000Z","y":-5.224},{"x":"2022-09-08T15:06:01.000Z","y":-5.468},{"x":"2022-09-08T15:06:02.000Z","y":-5.647},{"x":"2022-09-08T15:06:03.000Z","y":-5.159},{"x":"2022-09-08T15:06:05.000Z","y":-5.4350000000000005},{"x":"2022-09-08T15:06:06.000Z","y":-5.045},{"x":"2022-09-08T15:06:07.000Z","y":-5.338},{"x":"2022-09-08T15:06:09.000Z","y":-5.256},{"x":"2022-09-08T15:06:10.000Z","y":-4.963},{"x":"2022-09-08T15:06:11.000Z","y":-4.882},{"x":"2022-09-08T15:06:13.000Z","y":-5.663},{"x":"2022-09-08T15:06:14.000Z","y":-6.168},{"x":"2022-09-08T15:06:16.000Z","y":-4.687}],[{"x":"2022-09-08T15:05:18.000Z","y":-2.262},{"x":"2022-09-08T15:05:19.000Z","y":-2.49},{"x":"2022-09-08T15:05:20.000Z","y":-1.367},{"x":"2022-09-08T15:05:22.000Z","y":-1.062},{"x":"2022-09-08T15:05:23.000Z","y":-2.213},{"x":"2022-09-08T15:05:24.000Z","y":-2.734},{"x":"2022-09-08T15:05:25.000Z","y":-2.0020000000000002},{"x":"2022-09-08T15:05:27.000Z","y":-2.1},{"x":"2022-09-08T15:05:28.000Z","y":-0.586},{"x":"2022-09-08T15:05:29.000Z","y":-0.782},{"x":"2022-09-08T15:05:31.000Z","y":-2.995},{"x":"2022-09-08T15:05:32.000Z","y":-2.23},{"x":"2022-09-08T15:05:33.000Z","y":-0.993},{"x":"2022-09-08T15:05:34.000Z","y":-2.49},{"x":"2022-09-08T15:05:36.000Z","y":-2.197},{"x":"2022-09-08T15:05:37.000Z","y":-2.605},{"x":"2022-09-08T15:05:38.000Z","y":-1.969},{"x":"2022-09-08T15:05:40.000Z","y":-0.635},{"x":"2022-09-08T15:05:41.000Z","y":-2.4250000000000003},{"x":"2022-09-08T15:05:42.000Z","y":-2.458},{"x":"2022-09-08T15:05:43.000Z","y":-0.684},{"x":"2022-09-08T15:05:45.000Z","y":-1.351},{"x":"2022-09-08T15:05:46.000Z","y":-2.213},{"x":"2022-09-08T15:05:47.000Z","y":-2.246},{"x":"2022-09-08T15:05:49.000Z","y":-1.416},{"x":"2022-09-08T15:05:50.000Z","y":-0.863},{"x":"2022-09-08T15:05:51.000Z","y":-2.116},{"x":"2022-09-08T15:05:53.000Z","y":-1.481},{"x":"2022-09-08T15:05:54.000Z","y":-1.6280000000000001},{"x":"2022-09-08T15:05:56.000Z","y":-2.083},{"x":"2022-09-08T15:05:57.000Z","y":0.178},{"x":"2022-09-08T15:05:58.000Z","y":-31.649},{"x":"2022-09-08T15:05:59.000Z","y":-0.245},{"x":"2022-09-08T15:06:01.000Z","y":-0.212},{"x":"2022-09-08T15:06:02.000Z","y":-0.228},{"x":"2022-09-08T15:06:03.000Z","y":-0.245},{"x":"2022-09-08T15:06:05.000Z","y":-0.228},{"x":"2022-09-08T15:06:06.000Z","y":-0.196},{"x":"2022-09-08T15:06:07.000Z","y":-0.228},{"x":"2022-09-08T15:06:09.000Z","y":-0.245},{"x":"2022-09-08T15:06:10.000Z","y":-0.245},{"x":"2022-09-08T15:06:11.000Z","y":-0.277},{"x":"2022-09-08T15:06:13.000Z","y":-0.179},{"x":"2022-09-08T15:06:14.000Z","y":-0.212},{"x":"2022-09-08T15:06:16.000Z","y":-0.212}]]

This is as far as I have gotten which I thought was bang on but it doesn't show up in the chart, it's just blank.

msg.payload =[
    {
        labels:["Torque"],
        series:["S1 Torque (Nm)", "S2 Torque (Nm)", "S4 Torque (Nm)","S5 Torque (Nm)"],
        data:[
            [msg.payload[0].map(obj => {return {x: obj.x, y: obj.y}})],
            [msg.payload[1].map(obj => {return {x: obj.x, y: obj.y}})],
            [msg.payload[2].map(obj => {return {x: obj.x, y: obj.y}})],
            [msg.payload[3].map(obj => {return {x: obj.x, y: obj.y}})]
        ]
    }
]

return msg;

result of which is:

[{"labels":["Torque"],"series":["S1 Torque (Nm)","S2 Torque (Nm)","S4 Torque (Nm)","S5 Torque (Nm)"],"data":[[[{"x":"2022-09-08T15:05:18.000Z","y":0},{"x":"2022-09-08T15:05:19.000Z","y":0},{"x":"2022-09-08T15:05:20.000Z","y":0},{"x":"2022-09-08T15:05:22.000Z","y":0},{"x":"2022-09-08T15:05:23.000Z","y":0},{"x":"2022-09-08T15:05:24.000Z","y":0},{"x":"2022-09-08T15:05:25.000Z","y":0},{"x":"2022-09-08T15:05:27.000Z","y":0},{"x":"2022-09-08T15:05:28.000Z","y":0},{"x":"2022-09-08T15:05:29.000Z","y":0},{"x":"2022-09-08T15:05:31.000Z","y":0},{"x":"2022-09-08T15:05:32.000Z","y":0},{"x":"2022-09-08T15:05:33.000Z","y":0},{"x":"2022-09-08T15:05:34.000Z","y":0},{"x":"2022-09-08T15:05:36.000Z","y":0},{"x":"2022-09-08T15:05:37.000Z","y":0},{"x":"2022-09-08T15:05:38.000Z","y":0},{"x":"2022-09-08T15:05:40.000Z","y":0},{"x":"2022-09-08T15:05:41.000Z","y":0},{"x":"2022-09-08T15:05:42.000Z","y":0},{"x":"2022-09-08T15:05:43.000Z","y":0},{"x":"2022-09-08T15:05:45.000Z","y":0},{"x":"2022-09-08T15:05:46.000Z","y":0},{"x":"2022-09-08T15:05:47.000Z","y":0},{"x":"2022-09-08T15:05:49.000Z","y":0},{"x":"2022-09-08T15:05:50.000Z","y":-0.01},{"x":"2022-09-08T15:05:51.000Z","y":0.027},{"x":"2022-09-08T15:05:53.000Z","y":0.002},{"x":"2022-09-08T15:05:54.000Z","y":0},{"x":"2022-09-08T15:05:56.000Z","y":0},{"x":"2022-09-08T15:05:57.000Z","y":0},{"x":"2022-09-08T15:05:58.000Z","y":0},{"x":"2022-09-08T15:05:59.000Z","y":0},{"x":"2022-09-08T15:06:01.000Z","y":0},{"x":"2022-09-08T15:06:02.000Z","y":0},{"x":"2022-09-08T15:06:03.000Z","y":0},{"x":"2022-09-08T15:06:05.000Z","y":0},{"x":"2022-09-08T15:06:06.000Z","y":0},{"x":"2022-09-08T15:06:07.000Z","y":0},{"x":"2022-09-08T15:06:09.000Z","y":0},{"x":"2022-09-08T15:06:10.000Z","y":0},{"x":"2022-09-08T15:06:11.000Z","y":0},{"x":"2022-09-08T15:06:13.000Z","y":0},{"x":"2022-09-08T15:06:14.000Z","y":0},{"x":"2022-09-08T15:06:16.000Z","y":0}]],[[{"x":"2022-09-08T15:05:18.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:19.000Z","y":0.068},{"x":"2022-09-08T15:05:20.000Z","y":0.063},{"x":"2022-09-08T15:05:22.000Z","y":0.049},{"x":"2022-09-08T15:05:23.000Z","y":0.068},{"x":"2022-09-08T15:05:24.000Z","y":0.068},{"x":"2022-09-08T15:05:25.000Z","y":0.096},{"x":"2022-09-08T15:05:27.000Z","y":0.068},{"x":"2022-09-08T15:05:28.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:29.000Z","y":0.063},{"x":"2022-09-08T15:05:31.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:32.000Z","y":0.065},{"x":"2022-09-08T15:05:33.000Z","y":0.065},{"x":"2022-09-08T15:05:34.000Z","y":0.065},{"x":"2022-09-08T15:05:36.000Z","y":0.049},{"x":"2022-09-08T15:05:37.000Z","y":0.065},{"x":"2022-09-08T15:05:38.000Z","y":0.065},{"x":"2022-09-08T15:05:40.000Z","y":0.063},{"x":"2022-09-08T15:05:41.000Z","y":0.065},{"x":"2022-09-08T15:05:42.000Z","y":0.068},{"x":"2022-09-08T15:05:43.000Z","y":0.065},{"x":"2022-09-08T15:05:45.000Z","y":0.06},{"x":"2022-09-08T15:05:46.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:47.000Z","y":0.077},{"x":"2022-09-08T15:05:49.000Z","y":0.077},{"x":"2022-09-08T15:05:50.000Z","y":0.053},{"x":"2022-09-08T15:05:51.000Z","y":0.065},{"x":"2022-09-08T15:05:53.000Z","y":0.051000000000000004},{"x":"2022-09-08T15:05:54.000Z","y":0.049},{"x":"2022-09-08T15:05:56.000Z","y":0.079},{"x":"2022-09-08T15:05:57.000Z","y":0.079},{"x":"2022-09-08T15:05:58.000Z","y":0.049},{"x":"2022-09-08T15:05:59.000Z","y":0.063},{"x":"2022-09-08T15:06:01.000Z","y":0.065},{"x":"2022-09-08T15:06:02.000Z","y":0.065},{"x":"2022-09-08T15:06:03.000Z","y":0.065},{"x":"2022-09-08T15:06:05.000Z","y":0.079},{"x":"2022-09-08T15:06:06.000Z","y":0.075},{"x":"2022-09-08T15:06:07.000Z","y":0.065},{"x":"2022-09-08T15:06:09.000Z","y":0.065},{"x":"2022-09-08T15:06:10.000Z","y":0.046},{"x":"2022-09-08T15:06:11.000Z","y":0.079},{"x":"2022-09-08T15:06:13.000Z","y":0.06},{"x":"2022-09-08T15:06:14.000Z","y":0.063},{"x":"2022-09-08T15:06:16.000Z","y":0.07}]],[[{"x":"2022-09-08T15:05:18.000Z","y":-5.712},{"x":"2022-09-08T15:05:19.000Z","y":-4.752},{"x":"2022-09-08T15:05:20.000Z","y":-5.159},{"x":"2022-09-08T15:05:22.000Z","y":-4.752},{"x":"2022-09-08T15:05:23.000Z","y":-4.817},{"x":"2022-09-08T15:05:24.000Z","y":-5.179},{"x":"2022-09-08T15:05:25.000Z","y":-4.931},{"x":"2022-09-08T15:05:27.000Z","y":-5.8420000000000005},{"x":"2022-09-08T15:05:28.000Z","y":-5.607},{"x":"2022-09-08T15:05:29.000Z","y":-5.696},{"x":"2022-09-08T15:05:31.000Z","y":-5.224},{"x":"2022-09-08T15:05:32.000Z","y":-4.963},{"x":"2022-09-08T15:05:33.000Z","y":-4.915},{"x":"2022-09-08T15:05:34.000Z","y":-5.484},{"x":"2022-09-08T15:05:36.000Z","y":-5.4030000000000005},{"x":"2022-09-08T15:05:37.000Z","y":-5.8580000000000005},{"x":"2022-09-08T15:05:38.000Z","y":-4.752},{"x":"2022-09-08T15:05:40.000Z","y":-4.296},{"x":"2022-09-08T15:05:41.000Z","y":-6.607},{"x":"2022-09-08T15:05:42.000Z","y":-5.077},{"x":"2022-09-08T15:05:43.000Z","y":-5.452},{"x":"2022-09-08T15:05:45.000Z","y":-5.029},{"x":"2022-09-08T15:05:46.000Z","y":-5.354},{"x":"2022-09-08T15:05:47.000Z","y":-5.549},{"x":"2022-09-08T15:05:49.000Z","y":-5.061},{"x":"2022-09-08T15:05:50.000Z","y":-4.963},{"x":"2022-09-08T15:05:51.000Z","y":-5.94},{"x":"2022-09-08T15:05:53.000Z","y":-5.142},{"x":"2022-09-08T15:05:54.000Z","y":-4.996},{"x":"2022-09-08T15:05:56.000Z","y":-5.37},{"x":"2022-09-08T15:05:57.000Z","y":-5.305},{"x":"2022-09-08T15:05:58.000Z","y":-5.614},{"x":"2022-09-08T15:05:59.000Z","y":-5.224},{"x":"2022-09-08T15:06:01.000Z","y":-5.468},{"x":"2022-09-08T15:06:02.000Z","y":-5.647},{"x":"2022-09-08T15:06:03.000Z","y":-5.159},{"x":"2022-09-08T15:06:05.000Z","y":-5.4350000000000005},{"x":"2022-09-08T15:06:06.000Z","y":-5.045},{"x":"2022-09-08T15:06:07.000Z","y":-5.338},{"x":"2022-09-08T15:06:09.000Z","y":-5.256},{"x":"2022-09-08T15:06:10.000Z","y":-4.963},{"x":"2022-09-08T15:06:11.000Z","y":-4.882},{"x":"2022-09-08T15:06:13.000Z","y":-5.663},{"x":"2022-09-08T15:06:14.000Z","y":-6.168},{"x":"2022-09-08T15:06:16.000Z","y":-4.687}]],[[{"x":"2022-09-08T15:05:18.000Z","y":-2.262},{"x":"2022-09-08T15:05:19.000Z","y":-2.49},{"x":"2022-09-08T15:05:20.000Z","y":-1.367},{"x":"2022-09-08T15:05:22.000Z","y":-1.062},{"x":"2022-09-08T15:05:23.000Z","y":-2.213},{"x":"2022-09-08T15:05:24.000Z","y":-2.734},{"x":"2022-09-08T15:05:25.000Z","y":-2.0020000000000002},{"x":"2022-09-08T15:05:27.000Z","y":-2.1},{"x":"2022-09-08T15:05:28.000Z","y":-0.586},{"x":"2022-09-08T15:05:29.000Z","y":-0.782},{"x":"2022-09-08T15:05:31.000Z","y":-2.995},{"x":"2022-09-08T15:05:32.000Z","y":-2.23},{"x":"2022-09-08T15:05:33.000Z","y":-0.993},{"x":"2022-09-08T15:05:34.000Z","y":-2.49},{"x":"2022-09-08T15:05:36.000Z","y":-2.197},{"x":"2022-09-08T15:05:37.000Z","y":-2.605},{"x":"2022-09-08T15:05:38.000Z","y":-1.969},{"x":"2022-09-08T15:05:40.000Z","y":-0.635},{"x":"2022-09-08T15:05:41.000Z","y":-2.4250000000000003},{"x":"2022-09-08T15:05:42.000Z","y":-2.458},{"x":"2022-09-08T15:05:43.000Z","y":-0.684},{"x":"2022-09-08T15:05:45.000Z","y":-1.351},{"x":"2022-09-08T15:05:46.000Z","y":-2.213},{"x":"2022-09-08T15:05:47.000Z","y":-2.246},{"x":"2022-09-08T15:05:49.000Z","y":-1.416},{"x":"2022-09-08T15:05:50.000Z","y":-0.863},{"x":"2022-09-08T15:05:51.000Z","y":-2.116},{"x":"2022-09-08T15:05:53.000Z","y":-1.481},{"x":"2022-09-08T15:05:54.000Z","y":-1.6280000000000001},{"x":"2022-09-08T15:05:56.000Z","y":-2.083},{"x":"2022-09-08T15:05:57.000Z","y":0.178},{"x":"2022-09-08T15:05:58.000Z","y":-31.649},{"x":"2022-09-08T15:05:59.000Z","y":-0.245},{"x":"2022-09-08T15:06:01.000Z","y":-0.212},{"x":"2022-09-08T15:06:02.000Z","y":-0.228},{"x":"2022-09-08T15:06:03.000Z","y":-0.245},{"x":"2022-09-08T15:06:05.000Z","y":-0.228},{"x":"2022-09-08T15:06:06.000Z","y":-0.196},{"x":"2022-09-08T15:06:07.000Z","y":-0.228},{"x":"2022-09-08T15:06:09.000Z","y":-0.245},{"x":"2022-09-08T15:06:10.000Z","y":-0.245},{"x":"2022-09-08T15:06:11.000Z","y":-0.277},{"x":"2022-09-08T15:06:13.000Z","y":-0.179},{"x":"2022-09-08T15:06:14.000Z","y":-0.212},{"x":"2022-09-08T15:06:16.000Z","y":-0.212}]]]}]

You are adding an extra [ ] around your map arrays, try removing them.
e.g.

  msg.payload[1].map(obj => {return {x: obj.x, y: obj.y}}),

@E1cid you have come to my rescue yet again!!! Ican't believe that was all it was. I hate myself for not posting sooner :joy: !! I have been at this for an entire working day. The highs and lows of node red lol.

Needless to say, this works.
For reference, what I had done was attempt to emulate this node-red github info thinking

data = [
         [torque mapping 1],
         [torque mapping 2],
         [torque mapping 4],
         [torque mapping 5]
]

Evidently not.

THANK YOU!!

I did say last time it is important to understand Json and Javascript objects, you will get better over time though.
Glad it helped
this function would work to (untested as no data to test against).

msg.payload =[
    {
        labels:["Torque"],
        series:["S1 Torque (Nm)", "S2 Torque (Nm)", "S4 Torque (Nm)","S5 Torque (Nm)"],
        data: msg.payload.map(arr => {
           return arr.map(obj => {
               return {x: obj.x, y: obj.y}
           })
        })
    }
]

return msg;

Notes
would probably join as key value object, then you probably be able to create series dynaically from key. then in first map use Object.values(msg.payload).map...... I say this as joining as array may cause issues, probably not with your code, but it's safer to join as object as you can not get repeeat items in array.
I would also add an if statemennt around the function that creates the payload array for chart, to check if there is 4 elements to the array or object, and return null to msg to stop flow if the db has not return 4 arrays that are of equal length.

You did paste data but to use it i would have to edit it and i am feeling extra lazy today.

I thought I had pasted useable data in the section 'code text box' but clealry I messed that up.
I remeber you saying about understanding Json and Javascript objects. I think I am getting better but I'm still a long way off.

Thank you again.

1 Like

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