Chart Services‎ > ‎

Line Chart

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

Line Chart

Spreadsheet Preview screenshot:

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


Example Code:

function doGet(){
  //Get the data from spreadsheet
  ssID ='SpreadsheetID';//Change it ro yours
  var SS = SpreadsheetApp.openById(ssID);
  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.newLineChart()
      .setTitle("Sales by store")
  var app = UiApp.createApplication().setTitle("AST Chart");
  return app;