Help displaying two lines on a chart from SQL data

Hello

I'm trying to display data pulled from an SQL database in a chart, i have a function that works with the array of data and displays the line chart no problem. but now i need to add a second (and possibly third) array of data and i dont know where to start with changing the function node or my object format to get two lines on the chart.

this is the function node i use to display my data (i did not write this, i found it online and it worked for me)



var payload=msg.msg1.payload.data;


var data_out=[];
var a1=[];

for(let i=0;i<payload.length;i++)
{
  


var temp1={ "x": (payload[i].Log_Dato_Tid), "y":parseInt( payload[i]["Weld_Imin_Profile_Fronius1"])};

a1.push(temp1)

 
 
 //
 
 
}

data_out=[a1];
msg.payload=[{
"series": ["count1","date1"],
"data":data_out,
"labels": ["count1","date1"]
}];

return msg;

I think i need to change it to somehow use msg.msg2.payload.data the same way it uses msg.msg1.payload.data
this is the object data that i input to this node it holds two seperate arrays each (trimmed down so it fits)

{"socketid":"ejwyffMtaCPRDatUAAAB","_msgid":"53b9d9c2.a543f8","msg1":{"payload":{"data":[{"Log_Dato_Tid":"2021-06-09T15:27:47.760Z","Weld_Imin_Profile_Fronius1":312},{"Log_Dato_Tid":"2021-06-09T06:15:16.426Z","Weld_Imin_Profile_Fronius1":1},{"Log_Dato_Tid":"2021-06-09T06:16:29.430Z","Weld_Imin_Profile_Fronius1":2},{"Log_Dato_Tid":"2021-06-09T06:17:42.230Z","Weld_Imin_Profile_Fronius1":3},{"Log_Dato_Tid":"2021-06-09T06:18:55.330Z","Weld_Imin_Profile_Fronius1":4},{"Log_Dato_Tid":"2021-06-09T06:20:08.230Z","Weld_Imin_Profile_Fronius1":5},{"Log_Dato_Tid":"2021-06-09T06:21:21.133Z","Weld_Imin_Profile_Fronius1":6},{"Log_Dato_Tid":"2021-06-09T06:22:34.133Z","Weld_Imin_Profile_Fronius1":7},{"Log_Dato_Tid":"2021-06-09T06:23:46.733Z","Weld_Imin_Profile_Fronius1":8},{"Log_Dato_Tid":"2021-06-09T06:24:59.733Z","Weld_Imin_Profile_Fronius1":9},{"Log_Dato_Tid":"2021-06-09T06:33:01.240Z","Weld_Imin_Profile_Fronius1":10},{"Log_Dato_Tid":"2021-06-09T06:34:14.340Z","Weld_Imin_Profile_Fronius1":11},{"Log_Dato_Tid":"2021-06-09T06:35:27.440Z","Weld_Imin_Profile_Fronius1":12},{"Log_Dato_Tid":"2021-06-09T06:36:40.240Z","Weld_Imin_Profile_Fronius1":13},{"Log_Dato_Tid":"2021-06-09T06:37:53.343Z","Weld_Imin_Profile_Fronius1":14},{"Log_Dato_Tid":"2021-06-09T06:39:06.143Z","Weld_Imin_Profile_Fronius1":15},{"Log_Dato_Tid":"2021-06-09T06:40:19.043Z","Weld_Imin_Profile_Fronius1":16},{"Log_Dato_Tid":"2021-06-09T06:41:31.743Z","Weld_Imin_Profile_Fronius1":17},{"Log_Dato_Tid":"2021-06-09T06:42:44.646Z","Weld_Imin_Profile_Fronius1":18},{"Log_Dato_Tid":"2021-06-09T06:43:57.746Z","Weld_Imin_Profile_Fronius1":19},{"Log_Dato_Tid":"2021-06-09T06:45:10.446Z","Weld_Imin_Profile_Fronius1":20},{"Log_Dato_Tid":"2021-06-09T06:46:23.346Z","Weld_Imin_Profile_Fronius1":21},{"Log_Dato_Tid":"2021-06-09T06:47:36.346Z","Weld_Imin_Profile_Fronius1":22},{"Log_Dato_Tid":"2021-06-09T06:48:49.146Z","Weld_Imin_Profile_Fronius1":23},{"Log_Dato_Tid":"2021-06-09T06:50:02.250Z","Weld_Imin_Profile_Fronius1":24},{"Log_Dato_Tid":"2021-06-09T06:51:15.150Z","Weld_Imin_Profile_Fronius1":25},{"Log_Dato_Tid":"2021-06-09T06:52:28.050Z","Weld_Imin_Profile_Fronius1":26},{"Log_Dato_Tid":"2021-06-09T06:53:40.950Z","Weld_Imin_Profile_Fronius1":27},{"Log_Dato_Tid":"2021-06-09T06:54:53.853Z","Weld_Imin_Profile_Fronius1":28},{"Log_Dato_Tid":"2021-06-09T07:04:24.056Z","Weld_Imin_Profile_Fronius1":29},{"Log_Dato_Tid":"2021-06-09T07:05:36.256Z","Weld_Imin_Profile_Fronius1":30},{"Log_Dato_Tid":"2021-06-09T07:06:48.260Z","Weld_Imin_Profile_Fronius1":31},{"Log_Dato_Tid":"2021-06-09T07:08:00.160Z","Weld_Imin_Profile_Fronius1":32},{"Log_Dato_Tid":"2021-06-09T07:09:12.160Z","Weld_Imin_Profile_Fronius1":33},{"Log_Dato_Tid":"2021-06-09T07:10:24.060Z","Weld_Imin_Profile_Fronius1":34},{"Log_Dato_Tid":"2021-06-09T07:11:35.763Z","Weld_Imin_Profile_Fronius1":35},{"Log_Dato_Tid":"2021-06-09T07:12:47.663Z","Weld_Imin_Profile_Fronius1":36},{"Log_Dato_Tid":"2021-06-09T07:13:59.463Z","Weld_Imin_Profile_Fronius1":37},{"Log_Dato_Tid":"2021-06-09T07:15:11.263Z","Weld_Imin_Profile_Fronius1":38},{"Log_Dato_Tid":"2021-06-09T07:16:23.366Z","Weld_Imin_Profile_Fronius1":39},{"Log_Dato_Tid":"2021-06-09T07:17:35.166Z","Weld_Imin_Profile_Fronius1":40},{"Log_Dato_Tid":"2021-06-09T07:18:46.766Z","Weld_Imin_Profile_Fronius1":41},{"Log_Dato_Tid":"2021-06-09T07:19:58.566Z","Weld_Imin_Profile_Fronius1":42},{"Log_Dato_Tid":"2021-06-09T07:21:10.366Z","Weld_Imin_Profile_Fronius1":43},{"Log_Dato_Tid":"2021-06-09T07:22:22.266Z","Weld_Imin_Profile_Fronius1":44},{"Log_Dato_Tid":"2021-06-09T07:23:34.470Z","Weld_Imin_Profile_Fronius1":45},{"Log_Dato_Tid":"2021-06-09T07:24:46.070Z","Weld_Imin_Profile_Fronius1":46},{"Log_Dato_Tid":"2021-06-09T07:25:58.170Z","Weld_Imin_Profile_Fronius1":47},{"Log_Dato_Tid":"2021-06-09T07:27:10.473Z","Weld_Imin_Profile_Fronius1":48},{"Log_Dato_Tid":"2021-06-09T07:31:31.473Z","Weld_Imin_Profile_Fronius1":49},{"Log_Dato_Tid":"2021-06-09T07:32:32.273Z","Weld_Imin_Profile_Fronius1":50},{"Log_Dato_Tid":"2021-06-09T07:35:23.676Z","Weld_Imin_Profile_Fronius1":51},{"Log_Dato_Tid":"2021-06-09T07:36:32.476Z","Weld_Imin_Profile_Fronius1":52},{"Log_Dato_Tid":"2021-06-09T07:37:33.076Z","Weld_Imin_Profile_Fronius1":53},{"Log_Dato_Tid":"2021-06-09T07:38:33.576Z","Weld_Imin_Profile_Fronius1":54},{"Log_Dato_Tid":"2021-06-09T07:39:34.080Z","Weld_Imin_Profile_Fronius1":55},{"Log_Dato_Tid":"2021-06-09T07:40:34.680Z","Weld_Imin_Profile_Fronius1":56},{"Log_Dato_Tid":"2021-06-09T07:43:05.580Z","Weld_Imin_Profile_Fronius1":57},{"Log_Dato_Tid":"2021-06-09T07:44:06.383Z","Weld_Imin_Profile_Fronius1":58},{"Log_Dato_Tid":"2021-06-09T07:48:07.483Z","Weld_Imin_Profile_Fronius1":59},{"Log_Dato_Tid":"2021-06-09T07:49:07.983Z","Weld_Imin_Profile_Fronius1":60},{"Log_Dato_Tid":"2021-06-09T07:50:08.586Z","Weld_Imin_Profile_Fronius1":61},{"Log_Dato_Tid":"2021-06-09T07:51:09.186Z","Weld_Imin_Profile_Fronius1":62},{"Log_Dato_Tid":"2021-06-09T07:52:09.686Z","Weld_Imin_Profile_Fronius1":63},{"Log_Dato_Tid":"2021-06-09T07:53:10.486Z","Weld_Imin_Profile_Fronius1":64},{"Log_Dato_Tid":"2021-06-09T07:54:10.986Z","Weld_Imin_Profile_Fronius1":65},{"Log_Dato_Tid":"2021-06-09T07:55:11.886Z","Weld_Imin_Profile_Fronius1":66},{"Log_Dato_Tid":"2021-06-09T07:58:31.390Z","Weld_Imin_Profile_Fronius1":67},{"Log_Dato_Tid":"2021-06-09T07:59:31.990Z","Weld_Imin_Profile_Fronius1":68},{"Log_Dato_Tid":"2021-06-09T08:00:32.590Z","Weld_Imin_Profile_Fronius1":69},{"Log_Dato_Tid":"2021-06-09T08:01:33.293Z","Weld_Imin_Profile_Fronius1":70},{"Log_Dato_Tid":"2021-06-09T08:02:33.993Z","Weld_Imin_Profile_Fronius1":71},{"Log_Dato_Tid":"2021-06-09T08:03:34.493Z","Weld_Imin_Profile_Fronius1":72},{"Log_Dato_Tid":"2021-06-09T08:04:35.493Z","Weld_Imin_Profile_Fronius1":73},{"Log_Dato_Tid":"2021-06-09T08:05:36.293Z","Weld_Imin_Profile_Fronius1":74},{"Log_Dato_Tid":"2021-06-09T08:06:36.796Z","Weld_Imin_Profile_Fronius1":75},{"Log_Dato_Tid":"2021-06-09T08:07:37.396Z","Weld_Imin_Profile_Fronius1":76},{"Log_Dato_Tid":"2021-06-09T08:08:37.896Z","Weld_Imin_Profile_Fronius1":77},{"Log_Dato_Tid":"2021-06-09T08:09:38.496Z","Weld_Imin_Profile_Fronius1":78},{"Log_Dato_Tid":"2021-06-09T08:10:38.996Z","Weld_Imin_Profile_Fronius1":79},{"Log_Dato_Tid":"2021-06-09T08:18:16.603Z","Weld_Imin_Profile_Fronius1":80},{"Log_Dato_Tid":"2021-06-09T08:19:17.503Z","Weld_Imin_Profile_Fronius1":81},,"topic":"06-09-2021"},"msg2":{"payload":{"data":[{"Log_Dato_Tid":"2021-06-08T06:13:23.763Z","Weld_Imin_Profile_Fronius1":1},{"Log_Dato_Tid":"2021-06-08T06:14:38.163Z","Weld_Imin_Profile_Fronius1":2},{"Log_Dato_Tid":"2021-06-08T06:15:53.263Z","Weld_Imin_Profile_Fronius1":3},{"Log_Dato_Tid":"2021-06-08T06:17:08.066Z","Weld_Imin_Profile_Fronius1":4},{"Log_Dato_Tid":"2021-06-08T06:18:22.666Z","Weld_Imin_Profile_Fronius1":5},{"Log_Dato_Tid":"2021-06-08T06:19:37.266Z","Weld_Imin_Profile_Fronius1":6},{"Log_Dato_Tid":"2021-06-08T06:26:02.270Z","Weld_Imin_Profile_Fronius1":7},{"Log_Dato_Tid":"2021-06-08T06:27:16.873Z","Weld_Imin_Profile_Fronius1":8},{"Log_Dato_Tid":"2021-06-08T06:46:27.683Z","Weld_Imin_Profile_Fronius1":9},{"Log_Dato_Tid":"2021-06-08T06:47:42.983Z","Weld_Imin_Profile_Fronius1":10},{"Log_Dato_Tid":"2021-06-08T06:48:58.283Z","Weld_Imin_Profile_Fronius1":11},{"Log_Dato_Tid":"2021-06-08T06:50:13.886Z","Weld_Imin_Profile_Fronius1":12},{"Log_Dato_Tid":"2021-06-08T06:51:29.586Z","Weld_Imin_Profile_Fronius1":13},{"Log_Dato_Tid":"2021-06-08T06:52:45.286Z","Weld_Imin_Profile_Fronius1":14},{"Log_Dato_Tid":"2021-06-08T06:55:31.186Z","Weld_Imin_Profile_Fronius1":15},{"Log_Dato_Tid":"2021-06-08T06:56:46.590Z","Weld_Imin_Profile_Fronius1":16},{"Log_Dato_Tid":"2021-06-08T06:58:02.190Z","Weld_Imin_Profile_Fronius1":17},"topic":"06-08-2021"}}

i have actually managed to get both the lines on one graph now with this code

var payload1=msg.msg1.payload.data;
var payload2=msg.msg2.payload.data;

var data_out=[];
var a1=[];
for(let i=0;i<payload1.length;i++)

{  


var temp1={ "x": (payload1[i].Log_Dato_Tid), "y":parseInt( payload1[i]["Weld_Imin_Profile_Fronius1"])};

a1.push(temp1)
}
 //
 

var a2=[];
for(let i=0;i<payload1.length;i++)

{
var temp2={ "x": (payload2[i].Log_Dato_Tid), "y":parseInt( payload1[i]["Weld_Imin_Profile_Fronius1"])};
a2.push(temp2)
}

data_out=[a1,a2];
msg.payload=[{
"series": ["count1","date1"],
"data":data_out,
"labels": ["count1","date1"]
}];

return msg;

, but something i overlooked was that the values for the X axis also includes the date my aim is to have the two lines on top of each other to campere them, could anybody help me how to remove the date part and leave only the time in the Log_dato_Tid data array

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