最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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);
发布评论

评论列表(0)

  1. 暂无评论