1
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);
0

2 Answers 2

4

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]
]);
Sign up to request clarification or add additional context in comments.

1 Comment

Very thankful for this, will accept when it allows me.
2

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]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.