谷歌图表脚本生成意外错误

时间:2013-07-02 23:26:23

标签: google-apps-script

每当我尝试从数据中加载图表时,我都会说“意外错误”。

我从1480行的数据表中加载了数据。通过谷歌菜单添加图表完美无瑕。

当我通过脚本添加它时,它失败并出现以下错误: “遇到错误:出现意外错误”

function doGet() {

   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheets()[0];
   var lastrow = (sheet.getLastRow());
   // Get the range of cells that store mining data.
   var mining = ss.getRange("A2:H"+lastrow);

   // For every row of mining data, generate a mining object.
   var miningObjects = getRowsData(sheet, mining);



     var dataload = Charts.newDataTable();
     dataload.addColumn(Charts.ColumnType.STRING, "Date");
     dataload.addColumn(Charts.ColumnType.NUMBER, "Hash");
     for(var i = 0; i<miningObjects.length;i++){
       var support = miningObjects[i]
       //Browser.msgBox(Utilities.formatDate(support.date, "GMT-4", "yyyy-MM-dd HH:mm")+"")
       dataload.addRow([Utilities.formatDate(support.date, "GMT-3", "yyyy-MM-dd HH:mm")+"", support.hash])

     }
         dataload.build();
     var lineChart = Charts.newLineChart()
         .build();

        var control = Charts.newStringFilter()
        .setFilterColumnLabel("Date")
        .build();


     var dashboard = Charts.newDashboardPanel()
         .setDataTable(dataload)
         .bind(control, lineChart)
         .build();

     var uiApp = UiApp.createApplication();

     dashboard.add(uiApp.createVerticalPanel()
                   .add(uiApp.createHorizontalPanel()
                           .add(lineChart)
                           .setSpacing(10)));

         uiApp.add(dashboard);
         ss.show(uiApp);

}

原始电子表格就在这里。出于测试目的,我只使用前两行。

https://docs.google.com/spreadsheet/ccc?key=0AsNSSsm28wUfdFFKRU5SaFdKWkhNVWw0dTlPbXJvOVE&usp=sharing

1 个答案:

答案 0 :(得分:1)

似乎这里发生了一些事情。不确定您是否真的想在日期上使用control过滤器。但是,为了让您能够正常工作 - 您还需要将过滤器控件添加到dashboard。请参阅下面的.add(control)

  dashboard.add(uiApp.createVerticalPanel()
                .add(uiApp.createHorizontalPanel()
                     .add(control)
                     .add(lineChart)
                     .setSpacing(10)));