これは、スプレッドシートの名前付き範囲にバインドされたチュートリアルに相当します。名前付き範囲には列見出しが含まれます。
function doGet() {
var uiApp = UiApp.createApplication();
var ssKey = "0At0FGJizRd-gdFo5bWZUUFRrUnRabENiRFdmT2o4WUE";
var ss = SpreadsheetApp.openById(ssKey);
var datasource = ss.getRangeByName("myRange").getValues();
Logger.log(datasource);
var data = Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, datasource [0] [0])
.addColumn(Charts.ColumnType.STRING, datasource [0] [1])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [2])
.addColumn(Charts.ColumnType.NUMBER, datasource [0] [3])
for (i=1;i<=datasource.length-1;i++){
Logger.log(datasource [i]);
data.addRow([datasource [i] [0], datasource [i] [1], datasource [i] [2], datasource [i] [3]])
};
data.build();
var ageFilter = Charts.newNumberRangeFilter()
.setFilterColumnLabel("Age")
.build();
var genderFilter = Charts.newCategoryFilter()
.setFilterColumnLabel("Gender")
.build();
var pieChart = Charts.newPieChart()
.setDataViewDefinition(Charts.newDataViewDefinition()
.setColumns([0,3]))
.build();
var tableChart = Charts.newTableChart()
.build();
var dashboard = Charts.newDashboardPanel()
.setDataTable(data)
.bind([ageFilter, genderFilter], [pieChart, tableChart])
.build();
dashboard.add(uiApp.createVerticalPanel()
.add(uiApp.createHorizontalPanel()
.add(ageFilter).add(genderFilter)
.setSpacing(70))
.add(uiApp.createHorizontalPanel()
.add(pieChart).add(tableChart)
.setSpacing(10)));
uiApp.add(dashboard);
return uiApp;
}