Pie Chart

Here is an example of Pie Chart which takes data from spreadsheet to build the chart.


Chart Preview Screenshot:

Spreadsheet Preview screenshot:

Here is the is the spreadsheet preview which serves as the data source for the chart.

Example Code:

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++){




  //Create and build chart

  var chart = Charts.newPieChart()


      .setTitle("Sales by store")



//Craeate an application, and add the chart to it

  var app = UiApp.createApplication().setTitle("AST Chart");


  return app;