无法将Array转换为Control []。尝试构建仪表板时出错

时间:2014-09-23 21:55:07

标签: google-apps-script

以下是我的代码

function doGet() {
  var ss = SpreadsheetApp.openById('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
  var s = ss.getSheetByName("Red Book");
  var datasource = s.getDataRange();

  var DateFilter = Charts.newNumberRangeFilter().setFilterColumnLabel("Date Entered");
  var LeasingAgentFilter = Charts.newStringFilter().setFilterColumnLabel("Leasing Agent Initials").build();
  var ResolutionFilter = Charts.newCategoryFilter().setFilterColumnLabel("Resolution").build();

  var pieChart = Charts.newPieChart()
      .setDataViewDefinition(Charts.newDataViewDefinition().setColumns([0, 3]))
      .build();

  var tableChart = Charts.newTableChart()
    .setDataViewDefinition(Charts.newDataViewDefinition().setColumns([1,4,5,10]))
    .build();
    Logger.log(datasource.getValues())  
  var dashboard = Charts.newDashboardPanel().setDataTable(datasource)  //****Error occurs here
      .bind([DateFilter, LeasingAgentFilter, ResolutionFilter], [pieChart, tableChart])
      .build();

  var uiApp = UiApp.createApplication();
  var filterPanel = uiApp.createVerticalPanel();
  var chartPanel = uiApp.createHorizontalPanel();
  filterPanel.add(DateFilter).add(LeasingAgentFilter).add(ResolutionFilter).setSpacing(10)
  chartPanel.add(tableChart).add(pieChart).setSpacing(10)

  dashboard.add(uiApp.createVerticalPanel().add(filterPanel).add(chartPanel));
  uiApp.add(dashboard);
  return uiApp;
}

记录器验证我的数据确实存在,所以我不确定我缺少什么。任何帮助表示赞赏......应该提到我是GAS的新手。

14年9月24日 尝试了以下内容:

var data = datasource.getDataTable();
:
:
:
var dashboard = Charts.newDashboardPanel().setDataTable(data)

和...

var dashboard = Charts.newDashboardPanel().setDataTable(datasource.getDataTables())

我已经消除了数据集中的所有空白以防万一,但无济于事。 所有人都有同样的错误......我按照谷歌的说明https://www.youtube.com/watch?v=3deomYqHKgA进行了操作,似乎对他们有用......不确定我做错了什么。

1 个答案:

答案 0 :(得分:2)

任何关心的人的工作代码......问题在于我在DateFilter上没有.build()

function doGet() {
  var ss = SpreadsheetApp.openById('1Eh1Pm9cNAa1VeubTGWgyRJHnatVPEOgmqW7fw4TLj4s');
  var s = ss.getSheetByName("Red Book");
  var data = s.getDataRange();
  //var data = datasource.getDataTable();

  var DateFilter = Charts.newCategoryFilter().setFilterColumnIndex(1).build();
  var LeasingAgentFilter = Charts.newStringFilter().setFilterColumnIndex(10).build();
  var ResolutionFilter = Charts.newCategoryFilter().setFilterColumnIndex(4).build();

  var pieChart = Charts.newPieChart().setDataViewDefinition(Charts.newDataViewDefinition().setColumns([4,10])).build();

  var tableChart = Charts.newTableChart().setDataViewDefinition(Charts.newDataViewDefinition().setColumns([1,4,5,10])).build();

  var dashboard = Charts.newDashboardPanel()
      .setDataTable(data)
      .bind([DateFilter, LeasingAgentFilter, ResolutionFilter], [pieChart, tableChart])
      .build();

  var uiApp = UiApp.createApplication();
  var filterPanel = uiApp.createVerticalPanel();
  var chartPanel = uiApp.createHorizontalPanel();
  filterPanel.add(DateFilter).add(LeasingAgentFilter).add(ResolutionFilter).setSpacing(10)
  chartPanel.add(tableChart).add(pieChart).setSpacing(10)

  dashboard.add(uiApp.createVerticalPanel().add(filterPanel).add(chartPanel));
  uiApp.add(dashboard);
  return uiApp;
}