javascript - Google Visualization: how to remove a column from a DataTable - Stack Overflow

in google visualization i have a ChartWrapper:table = new google.visualization.ChartWrapper({'char

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?

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?

Share Improve this question asked Jul 23, 2014 at 14:24 TomTom 4,10725 gold badges72 silver badges107 bronze badges 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 Commented Jul 24, 2014 at 0:08
Add a ment  | 

1 Answer 1

Reset to default 8

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745119234a4612315.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信