Question

var data = google.visualization.arrayToDataTable([
    ['Year', 'Oil', 'Cost', 'Barrel'],
    ['2004',  1000, 400,    710],
    ['2005',  1170, 460,    850],
    ['2006',  660,  1120,   620]
  ]);

I have the above example, but say I want to add ['2007', 1030, 540, 740] to the end of that outside of the above?

I tried the following but it comes up with push is not a function

setTimeout(function(){
      data.push(['2007',  1030, 540, 740]);
    chart.draw(data, options);
  }, 1000);
Was it helpful?

Solution

Hi Take a look at this: https://developers.google.com/chart/interactive/docs/reference#DataTable_constructors (see section Details)

data is datatable, so it has a method for adding a row onto it. You don't push into it.

What you probably want is this:

data.addRows([
  ['2007', 1030, 540, 740]
]);

OTHER TIPS

It is the DataTable and looking into the documentation, it seems it has a separate method can addRows() to add data to it.

data.addRows(['2007',  1030,      540, 740]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top