Home » Javascript » How to use google line chart two different length arrays

How to use google line chart two different length arrays

Posted by: admin June 30, 2018 Leave a comment

Questions:

I am trying to draw a Google Line Chart, where each line may have a different number of data points. This is my array format one with length 2 and one with length 3 . I dont know how to solve this problem , any help is appreciable

Array [ Date 2018-05-04T18:30:00.000Z, 45 ]
Array [ Date 2018-05-22T18:30:00.000Z, 234, 234, 234 ]

This is the code that i am using for plotting the graph , here both my columns and rows are dynamic.

for (var k = 0; k < data1.queryA.length; k++) {
  data.addColumn('number', data1.queryA[k].keyword);
}
for (var i = 0; i < data1.query.length; i++) {
  var arr = [];
  alert(data1.query[i].date.length);
  for (var j = 0; j < data1.query[i].date.length; j++) {
    arr.push(parseInt(data1.query[i].date[j].page));
  }
  var test = [new Date(data1.query[i].datee)];
  console.log(test.concat(arr));
  data.addRow(test.concat(arr));
}
Answers: