[Google Apps Script] Build a line chart from an array

Created on November 29, 2026

You can use a DataTable to turn an array into a Chart object. This example builds a line chart of scores by date.

const rows = [
  ['2019-01-01', 100],
  ['2019-01-02', 90],
  ['2019-01-03', 110],
];

const dataTable = Charts.newDataTable()
  .addColumn(Charts.ColumnType.STRING, 'Date')
  .addColumn(Charts.ColumnType.NUMBER, 'Score');

for (const row of rows) {
  dataTable.addRow(row);
}

const chart = Charts.newLineChart()
  .setDataTable(dataTable)
  .setTitle('Daily scores')
  .setDimensions(2000, 1000)
  .build();
  • Charts.newDataTable() creates a builder. addColumn() defines a string column for the dates and a numeric column for the scores.
  • addRow() adds each date and score to the table.
  • Charts.newLineChart() creates a line chart builder. setDataTable() supplies the data, and setTitle() and setDimensions() set the chart title and size in pixels.
  • build() returns the Chart object.

Reference

Google Apps Script