Column Chart
Here is an example of Column Chart which takes data from spreadsheet to build the chart.
References:
Chart Preview Screenshot:
Spreadsheet Preview screenshot:
Here is the is the spreadsheet preview which serves as the data source for the chart.
function doGet(){
//Get the data from spreadsheet
var SS = SpreadsheetApp.openById('SpreadsheetID');//Change it to yours
var sheet = SS.getSheets()[0];
var data = sheet.getRange('A1:G7').getValues();
//Build data table
var dataTable = Charts.newDataTable();
//Add Column types
dataTable.addColumn(Charts.ColumnType.STRING, data[0][0]);
for(var i=1; i<data[0].length-1; i++){
dataTable.addColumn(Charts.ColumnType.NUMBER, data[0][i]);
}
//Add rows
for(var j=1; j<data.length; j++){
dataTable.addRow(data[j]);
}
//Create and build chart
var chart = Charts.newColumnChart()
.setDataTable(dataTable)
.setTitle("Sales by store")
.build();
//Craeate an application, and add the chart to it
var app = UiApp.createApplication().setTitle("AST Chart");
app.add(chart)
return app;
}
Example Code: