Class Charts

  • The Charts service is the entry point for creating charts in scripts.

  • You can create various chart types like Area, Bar, Column, Line, Pie, Scatter, and Table charts using this service.

  • Data for charts is held in a DataTable, which can be built manually.

  • Charts can be added to a web page as an image.

Charts

Entry point for creating Charts in scripts.

This example creates a basic data table, populates an area chart with the data, and adds itinto a web page as an image:

functiondoGet(){constdata=Charts.newDataTable().addColumn(Charts.ColumnType.STRING,'Month').addColumn(Charts.ColumnType.NUMBER,'In Store').addColumn(Charts.ColumnType.NUMBER,'Online').addRow(['January',10,1]).addRow(['February',12,1]).addRow(['March',20,2]).addRow(['April',25,3]).addRow(['May',30,4]).build();constchart=Charts.newAreaChart().setDataTable(data).setStacked().setRange(0,40).setTitle('Sales per Month').build();consthtmlOutput=HtmlService.createHtmlOutput().setTitle('My Chart');constimageData=Utilities.base64Encode(chart.getAs('image/png').getBytes());constimageUrl=`data:image/png;base64,${encodeURI(imageData)}`;htmlOutput.append('Render chart server side: <br/>');htmlOutput.append(`<img border="1" src="${imageUrl}">`);returnhtmlOutput;}

Properties

PropertyTypeDescription
ChartHiddenDimensionStrategyChartHiddenDimensionStrategyAn enumeration of how hidden dimensions in a source are expressed in a chart.
ChartMergeStrategyChartMergeStrategyAn enumeration of how multiple ranges in the source are expressed in a chart.
ChartTypeChartTypeAn enumeration of chart types supported by the Charts service.
ColumnTypeColumnTypeAn enumeration of the valid data types for columns in aDataTable.
CurveStyleCurveStyleAn enumeration of the styles for curves in a chart.
PointStylePointStyleAn enumeration of the styles of points in a line.
PositionPositionAn enumeration of legend positions within a chart.

Methods

MethodReturn typeBrief description
newAreaChart()AreaChartBuilderStarts building an area chart, as described in theGoogle ChartTools documentation.
newBarChart()BarChartBuilderStarts building a bar chart, as described in theGoogle ChartTools documentation.
newColumnChart()ColumnChartBuilderStarts building a column chart, as described in theGoogle ChartTools documentation.
newDataTable()DataTableBuilderCreates an empty data table, which can have its values set manually.
newDataViewDefinition()DataViewDefinitionBuilderCreates a new data view definition.
newLineChart()LineChartBuilderStarts building a line chart, as described in theGoogle ChartTools documentation.
newPieChart()PieChartBuilderStarts building a pie chart, as described in theGoogle ChartTools documentation.
newScatterChart()ScatterChartBuilderStarts building a scatter chart, as described in theGoogle ChartTools documentation.
newTableChart()TableChartBuilderStarts building a table chart, as described in theGoogle ChartTools documentation.
newTextStyle()TextStyleBuilderCreates a new text style builder.

Detailed documentation

newAreaChart()

Starts building an area chart, as described in theGoogle ChartTools documentation.

Return

AreaChartBuilder — An AreaChartBuilder, which can be used to build an area chart.


newBarChart()

Starts building a bar chart, as described in theGoogle ChartTools documentation.

Return

BarChartBuilder — A BarChartBuilder, which can be used to build a bar chart.


newColumnChart()

Starts building a column chart, as described in theGoogle ChartTools documentation.

Return

ColumnChartBuilder — A ColumnChartBuilder, which can be used to build a column chart.


newDataTable()

Creates an empty data table, which can have its values set manually.

Data tables hold the data for all chart types.

Return

DataTableBuilder — A DataTableBuilder, which can hold data for charts.


newDataViewDefinition()

Creates a new data view definition.

Use setters to define the different properties of the data view.

Return

DataViewDefinitionBuilder — A DataViewDefinitionBuilder, which can be used to build a data view definition.


newLineChart()

Starts building a line chart, as described in theGoogle ChartTools documentation.

Return

LineChartBuilder — A LineChartBuilder, which can be used to build a line chart.


newPieChart()

Starts building a pie chart, as described in theGoogle ChartTools documentation.

Return

PieChartBuilder — A PieChartBuilder, which can be used to build a pie chart.


newScatterChart()

Starts building a scatter chart, as described in theGoogle ChartTools documentation.

Return

ScatterChartBuilder — A ScatterChartBuilder, which can be used to build a scatter chart.


newTableChart()

Starts building a table chart, as described in theGoogle ChartTools documentation.

Return

TableChartBuilder — A TableChartBuilder, which can be used to build a table chart.


newTextStyle()

Creates a new text style builder.

To change the default values, use the setter functions.

Return

TextStyleBuilder — A TextStyleBuilder, which can be used to build a text style configuration object.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.