0
votes

in google visualization i have a ChartWrapper:

table = new google.visualization.ChartWrapper({
      'chartType': 'Table',
      'containerId': 'table_div',
      'options': {
          'allowHtml': true,
      }, 
    });

I'd like to export to csv the data visualized in the table (after make some filter) So i get the Data Table:

var dataTableTmp = table.getDataTable();

Now if i try to remove a column from the dataTable:

dataTableTmp.removeColumn(0); 

i get the following error:

Uncaught TypeError: undefined is not a function

What is the problem?

1
What is the purpose of removing the column? There are a couple of different approaches you can take, and which one you use depends largely on what you want to do with the data afterwards.asgallant

1 Answers

7
votes

The getDataTable method returns whatever object is passed to the ChartWrapper's dataTable parameter. In the case of Dashboards, the ChartWrapper actually receives a DataView, not a DataTable. There are a couple of different approaches you can take to "remove" the column, depending on what you want to accomplish by removing it.

If all you need to do is read from the data, ignoring the first column, the simplest solution is to iterate over the columns starting at index 1, not 0.

You can also create a new DataView based on the existing data and restrict the columns in the view, eg:

var view = new google.visualization.DataView(dataTableTmp);
view.setColumns([1, 2, 3, 4 /* etc... */]);

You can also convert the DataView to an actual DataTable, and then remove the column from the DataTable:

var dt = dataTableTmp.toDataTable();
dt.removeColumn(0);