0

我收到“对象类型与列类型不匹配”错误,不知道为什么......不确定我的代码是否有问题(很可能)或者它是否不接受仪表板。我认为我的错误与数据源以及我如何从电子表格中提取数据有关。

function doGet() {
  var app = UiApp.createApplication().setTitle('DHS: Kurzweil Calendar');

  //Create stack panel
  var stackPanel = app.createStackPanel().setSize('100%', '100%');
  var info = about(app);
  var p1 = app.createVerticalPanel().setId('vrtPanel1').add(info);
  var cal = calendar(app);
  var p2 = app.createVerticalPanel().setId('vrtPanel2').add(cal);
  var form = formBuild(app);
  var p3 = app.createVerticalPanel().setId('vrtPanel3').add(form);

  //add widgets to each stack panel, and name the stack panel
  stackPanel.add(p1, 'About the Lab');
  stackPanel.add(p2, 'Lab Calendar');
  stackPanel.add(p3, 'Lab Scheduling');

  //Add the panel to the application
  app.add(stackPanel);
  return app;
}

function about(app){
  return app.createHTML('<br />' + 
                        '<p>The Kurzweil Lab at Davie High School supports <i>20 independent student workstations</i> and is designed for the specific use of Kurzweil software.  The lab\'s main objective is to support students who have a Read-Aloud accommodation on their Individual Education Plan (IEP).  If a student does not have a Read-Aloud accommodation, but has another accommodation like: Separate Setting, Extended Time, or English as a Second Language (ESL) then they are welcome in the lab as long as the lab is not full.  If the lab reaches capacity and Read-Aloud students need to use Kurzweil, the student(s) without a Read-Aloud accommodation or who are refusing their Read-Aloud accommodation will be asked to go back to their classroom so that the teacher can make other arrangements for that student.</p>' + 
                        '<p>During non-testing situations the Kurzweil Lab can be scheduled by EC teachers to help with study skills, individual projects, or other work that requires the use of a computer lab.</p>', true);
}

function calendar(app){
  // Create Data Source
  var ss = SpreadsheetApp.openById('0Aur3owCpuUY-dGJIOGZ1LXhqT2FNMGVXSGNJazFnUmc');
  var datasource = ss.getSheetByName('Schedule').getRange(1,1,ss.getLastRow(),ss.getLastColumn());

  // Create Charts and Controls
  var dateFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Date").build();
  var teacherFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Teacher").build();
  var subjectFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Subject").build();
  var periodFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Period").build();
  var typeFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Type").build();
  var tableChart = Charts.newTableChart().build();

  //Create and bind Dashboard
  var dashboard = Charts.newDashboardPanel()
      .setDataTable(datasource)
      .bind([dateFilter, teacherFilter, subjectFilter, periodFilter, typeFilter], [tableChart])
      .build();

  //Create Application
  dashboard.add(app.createVerticalPanel()
                .add(app.createHorizontalPanel()
                     .add(dateFilter).add(teacherFilter).add(subjectFilter).add(periodFilter).add(typeFilter)
                     .setSpacing(70))
                .add(app.createHorizontalPanel()
                     .add(tableChart)
                     .setSpacing(10)));

  //Add the panel to the application
  app.add(dashboard);
  return app;
}
4

1 回答 1

0

您只是忘记了您更改了构建 UI 的每个函数返回数据的方式...如果您还记得您关于 stackPanels 的第一篇文章,我们将调用更改为

  var cal = calendar(app);

进而

  var p2 = app.createVerticalPanel().setId('vrtPanel2').add(cal);

所以我们显然期望得到一个 Ui 对象(一个小部件)作为回报。

您可以简单地更改以下function calendar(app){类似的结尾:

  ...
  dashboard.add(app.createVerticalPanel()
                .add(app.createHorizontalPanel()
                     .add(dateFilter).add(teacherFilter).add(subjectFilter).add(periodFilter).add(typeFilter)
                     .setSpacing(70))
                .add(app.createHorizontalPanel()
                     .add(tableChart)
                     .setSpacing(10)));

  //Add the panel to the application
  return dashboard;// return the dashboard itself, not the app.
}

编辑:这绝对是简单的事实......我的回答是正确的,但显然不包括仪表板构建的问题。

经过一些研究(我以前从未使用过 Charts 服务),我发现这段代码不会产生任何错误,但我绝对不确定它会返回你想要的东西......

尽管如此,它应该可以帮助您找到自己的方式。(如果看起来不正确,请不要怪我;-)

function calendar(app){
  // Create Data Source
  var ss = SpreadsheetApp.openById('0Aur3owCpuUY-dGJIOGZ1LXhqT2FNMGVXSGNJazFnUmc');
  var sh = ss.getSheetByName('Schedule');
  var datasource = sh.getRange(1,2,sh.getLastRow(),sh.getLastColumn()).getValues();
  Logger.log(datasource)
  var dataTable = Charts.newDataTable();
  for( var j in datasource[0] ){
  dataTable.addColumn(Charts.ColumnType.STRING, datasource[0][j]);
  }
  for( var i = 1; i < datasource.length; ++i ){
  dataTable.addRow(datasource[i].map(String));
  }
var dashboard = Charts.newDashboardPanel().setDataTable(dataTable);  // Create Charts and Controls
  var dateFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Date").setDataTable(dataTable).build();
  var teacherFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Teacher").setDataTable(dataTable).build();
  var subjectFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Subject").setDataTable(dataTable).build();
  var periodFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Period").setDataTable(dataTable).build();
  var typeFilter = Charts.newCategoryFilter()
      .setFilterColumnLabel("Type").setDataTable(dataTable).build();
  var tableChart = Charts.newTableChart().setDimensions(1000, 600).setDataTable(dataTable).build();

  //Create and bind Dashboard
  var dashboard = Charts.newDashboardPanel()
      .setDataTable(dataTable)
      .bind([dateFilter, teacherFilter, subjectFilter, periodFilter, typeFilter], [tableChart])
      .build();

  //Create Application
  var dashBoardPanel = app.createVerticalPanel()
  dashBoardPanel.add(app.createHorizontalPanel()
                     .add(dateFilter).add(teacherFilter).add(subjectFilter).add(periodFilter).add(typeFilter)
                     .setSpacing(30));
  dashBoardPanel.add(tableChart);

  //Add the panel to the application
  return dashBoardPanel;
}

编辑2:要将第一列作为日期,您必须稍微修改for loops填充的日期,dataTables以便您只能从第二列转换为字符串。

我是这样做的:

function calendar(app){
      // Create Data Source
      var ss = SpreadsheetApp.openById('0Aur3owCpuUY-dGJIOGZ1LXhqT2FNMGVXSGNJazFnUmc');
      var sh = ss.getSheetByName('Schedule');
      var datasource = sh.getRange(1,1,sh.getLastRow(),sh.getLastColumn()).getValues();
      Logger.log(datasource)
      var dataTable = Charts.newDataTable();
      dataTable.addColumn(Charts.ColumnType.DATE, datasource[0][1]);
      for( var j=2 ;j< datasource[0].length ;++j ){
        dataTable.addColumn(Charts.ColumnType.STRING, datasource[0][j]);
      }
      for( var i = 1; i < datasource.length; ++i ){
        var datarow = [];
        datarow.push(datasource[i][1]);
        for( var j=2 ;j< datasource[0].length ;++j ){
          datarow.push(datasource[i][j].toString());
        }
        dataTable.addRow(datarow);
      }
         var dashboard = Charts.newDashboardPanel().setDataTable(dataTable);  // Create Charts and Controls
          ...

在此处输入图像描述

于 2013-10-11T16:33:28.687 回答