Charts Service

Charts

This service allows users to create charts using Google Charts Tools and render them server side. If you want to render charts in a web browser, use the Google Charts API instead.

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

function doGet() {
  var data = 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();

  var chart = Charts.newAreaChart()
      .setDataTable(data)
      .setStacked()
      .setRange(0, 40)
      .setTitle('Sales per Month')
      .build();

  var htmlOutput = HtmlService.createHtmlOutput().setTitle('My Chart');
  var imageData = Utilities.base64Encode(chart.getAs('image/png').getBytes());
  var imageUrl = "data:image/png;base64," + encodeURI(imageData);
  htmlOutput.append("Render chart server side: <br/>");
  htmlOutput.append("<img border=\"1\" src=\"" + imageUrl + "\">");
  return htmlOutput;

}

Classes

Name Brief description
AreaChartBuilder Builder for area charts.
BarChartBuilder Builder for bar charts.
Chart A Chart object, which can be converted to a static image.
ChartHiddenDimensionStrategy An enumeration of how hidden dimensions in a source are expressed in a chart.
ChartMergeStrategy An enumeration of how multiple ranges in the source are expressed in a chart.
ChartOptions Exposes options currently configured for a Chart, such as height, color, etc.
ChartType Chart types supported by the Charts service.
Charts Entry point for creating Charts in scripts.
ColumnChartBuilder Builder for column charts.
ColumnType An enumeration of the valid data types for columns in a DataTable.
CurveStyle An enumeration of the styles for curves in a chart.
DataTable A Data Table to be used in charts.
DataTableBuilder Builder of DataTable objects.
DataTableSource Interface for objects that can represent their data as a DataTable.
DataViewDefinition A data view definition for visualizing chart data.
DataViewDefinitionBuilder Builder for DataViewDefinition objects.
LineChartBuilder Builder for line charts.
MatchType An enumeration of how a string value should be matched.
NumberRangeFilterBuilder A builder for number range filter controls.
Orientation An enumeration of the orientation of an object.
PickerValuesLayout An enumeration of how to display selected values in picker widget.
PieChartBuilder A builder for pie charts.
PointStyle An enumeration of the styles of points in a line.
Position An enumeration of legend positions within a chart.
ScatterChartBuilder Builder for scatter charts.
StringFilterBuilder A builder for string filter controls.
TableChartBuilder A builder for table charts.
TextStyle A text style configuration object.
TextStyleBuilder A builder used to create TextStyle objects.

AreaChartBuilder

Methods

Method Return type Brief description
build() Chart Builds the chart.
reverseCategories() AreaChartBuilder Reverses the drawing of series in the domain axis.
setBackgroundColor(cssValue) AreaChartBuilder Sets the background color for the chart.
setColors(cssValues) AreaChartBuilder Sets the colors for the lines in the chart.
setDataSourceUrl(url) AreaChartBuilder Sets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder) AreaChartBuilder Sets the data table to use for the chart using a DataTableBuilder.
setDataTable(table) AreaChartBuilder Sets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition) AreaChartBuilder Sets the data view definition to use for the chart.
setDimensions(width, height) AreaChartBuilder Sets the dimensions for the chart.
setLegendPosition(position) AreaChartBuilder Sets the position of the legend with respect to the chart.
setLegendTextStyle(textStyle) AreaChartBuilder Sets the text style of the chart legend.
setOption(option, value) AreaChartBuilder Sets advanced options for this chart.
setPointStyle(style) AreaChartBuilder Sets the style for points in the line.
setRange(start, end) AreaChartBuilder Sets the range for the chart.
setStacked() AreaChartBuilder Uses stacked lines, meaning that line and bar values are stacked (accumulated).
setTitle(chartTitle) AreaChartBuilder Sets the title of the chart.
setTitleTextStyle(textStyle) AreaChartBuilder Sets the text style of the chart title.
setXAxisTextStyle(textStyle) AreaChartBuilder Sets the horizontal axis text style.
setXAxisTitle(title) AreaChartBuilder Adds a title to the horizontal axis.
setXAxisTitleTextStyle(textStyle) AreaChartBuilder Sets the horizontal axis title text style.
setYAxisTextStyle(textStyle) AreaChartBuilder Sets the vertical axis text style.
setYAxisTitle(title) AreaChartBuilder Adds a title to the vertical axis.
setYAxisTitleTextStyle(textStyle) AreaChartBuilder Sets the vertical axis title text style.
useLogScale() AreaChartBuilder Makes the range axis into a logarithmic scale (requires all values to be positive).

BarChartBuilder

Methods

Method Return type Brief description
build() Chart Builds the chart.
reverseCategories() BarChartBuilder Reverses the drawing of series in the domain axis.
reverseDirection() BarChartBuilder Reverses the direction in which the bars grow along the horizontal axis.
setBackgroundColor(cssValue) BarChartBuilder Sets the background color for the chart.
setColors(cssValues) BarChartBuilder Sets the colors for the lines in the chart.
setDataSourceUrl(url) BarChartBuilder Sets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder) BarChartBuilder Sets the data table to use for the chart using a DataTableBuilder.
setDataTable(table) BarChartBuilder Sets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition) BarChartBuilder Sets the data view definition to use for the chart.
setDimensions(width, height) BarChartBuilder Sets the dimensions for the chart.
setLegendPosition(position) BarChartBuilder Sets the position of the legend with respect to the chart.
setLegendTextStyle(textStyle) BarChartBuilder Sets the text style of the chart legend.
setOption(option, value) BarChartBuilder Sets advanced options for this chart.
setRange(start, end) BarChartBuilder Sets the range for the chart.
setStacked() BarChartBuilder Uses stacked lines, meaning that line and bar values are stacked (accumulated).
setTitle(chartTitle) BarChartBuilder Sets the title of the chart.
setTitleTextStyle(textStyle) BarChartBuilder Sets the text style of the chart title.
setXAxisTextStyle(textStyle) BarChartBuilder Sets the horizontal axis text style.
setXAxisTitle(title) BarChartBuilder Adds a title to the horizontal axis.
setXAxisTitleTextStyle(textStyle) BarChartBuilder Sets the horizontal axis title text style.
setYAxisTextStyle(textStyle) BarChartBuilder Sets the vertical axis text style.
setYAxisTitle(title) BarChartBuilder Adds a title to the vertical axis.
setYAxisTitleTextStyle(textStyle) BarChartBuilder Sets the vertical axis title text style.
useLogScale() BarChartBuilder Makes the range axis into a logarithmic scale (requires all values to be positive).

Chart

Methods

Method Return type Brief description
getAs(contentType) Blob Return the data inside this object as a blob converted to the specified content type.
getBlob() Blob Return the data inside this object as a blob.
getOptions() ChartOptions Returns the options for this chart, such as height, colors, and axes.

ChartHiddenDimensionStrategy

Properties

Property Type Description
IGNORE_BOTH Enum Default; charts skips any hidden columns and hidden rows.
IGNORE_ROWS Enum Charts skips hidden rows only.
IGNORE_COLUMNS Enum Charts skips hidden columns only.
SHOW_BOTH Enum Charts does not skip hidden columns or hidden rows.

ChartMergeStrategy

Properties

Property Type Description
MERGE_COLUMNS Enum Default.
MERGE_ROWS Enum Charts merges the rows of multiple ranges.

ChartOptions

Methods

Method Return type Brief description
get(option) Object Returns a configured option for this chart.
getOrDefault(option) Object Returns a configured option for this chart.

ChartType

Properties

Property Type Description
TIMELINE Enum Timeline chart.
AREA Enum Area chart
BAR Enum Bar chart
BUBBLE Enum Bubble chart.
CANDLESTICK Enum Candlestick chart.
COLUMN Enum Column chart
COMBO Enum Combo chart
GAUGE Enum Gauge chart.
GEO Enum Geo chart.
HISTOGRAM Enum Histogram
RADAR Enum Radar chart.
LINE Enum Line chart
ORG Enum Org chart.
PIE Enum Pie chart
SCATTER Enum Scatter chart
SPARKLINE Enum Sparkline chart.
STEPPED_AREA Enum Stepped area chart.
TABLE Enum Table chart
TREEMAP Enum Treemap chart.
WATERFALL Enum Waterfall chart.

Charts

Properties

Property Type Description
ChartHiddenDimensionStrategy ChartHiddenDimensionStrategy An enumeration of how hidden dimensions in a source are expressed in a chart.
ChartMergeStrategy ChartMergeStrategy An enumeration of how multiple ranges in the source are expressed in a chart.
ChartType ChartType An enumeration of chart types supported by the Charts service.
ColumnType ColumnType An enumeration of the valid data types for columns in a DataTable.
CurveStyle CurveStyle An enumeration of the styles for curves in a chart.
PointStyle PointStyle An enumeration of the styles of points in a line.
Position Position An enumeration of legend positions within a chart.

Methods

Method Return type Brief description
newAreaChart() AreaChartBuilder Starts building an area chart, as described in the Google Chart Tools documentation.
newBarChart() BarChartBuilder Starts building a bar chart, as described in the Google Chart Tools documentation.
newColumnChart() ColumnChartBuilder Starts building a column chart, as described in the Google Chart Tools documentation.
newDataTable() DataTableBuilder Creates an empty data table, which can have its values set manually.
newDataViewDefinition() DataViewDefinitionBuilder Creates a new data view definition.
newLineChart() LineChartBuilder Starts building a line chart, as described in the Google Chart Tools documentation.
newPieChart() PieChartBuilder Starts building a pie chart, as described in the Google Chart Tools documentation.
newScatterChart() ScatterChartBuilder Starts building a scatter chart, as described in the Google Chart Tools documentation.
newTableChart() TableChartBuilder Starts building a table chart, as described in the Google Chart Tools documentation.
newTextStyle() TextStyleBuilder Creates a new text style builder.

ColumnChartBuilder

Methods

Method Return type Brief description
build() Chart Builds the chart.
reverseCategories() ColumnChartBuilder Reverses the drawing of series in the domain axis.
setBackgroundColor(cssValue) ColumnChartBuilder Sets the background color for the chart.
setColors(cssValues) ColumnChartBuilder Sets the colors for the lines in the chart.
setDataSourceUrl(url) ColumnChartBuilder Sets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder) ColumnChartBuilder Sets the data table to use for the chart using a DataTableBuilder.
setDataTable(table) ColumnChartBuilder Sets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition) ColumnChartBuilder Sets the data view definition to use for the chart.
setDimensions(width, height) ColumnChartBuilder Sets the dimensions for the chart.
setLegendPosition(position) ColumnChartBuilder Sets the position of the legend with respect to the chart.
setLegendTextStyle(textStyle) ColumnChartBuilder Sets the text style of the chart legend.
setOption(option, value) ColumnChartBuilder Sets advanced options for this chart.
setRange(start, end) ColumnChartBuilder Sets the range for the chart.
setStacked() ColumnChartBuilder Uses stacked lines, meaning that line and bar values are stacked (accumulated).
setTitle(chartTitle) ColumnChartBuilder Sets the title of the chart.
setTitleTextStyle(textStyle) ColumnChartBuilder Sets the text style of the chart title.
setXAxisTextStyle(textStyle) ColumnChartBuilder Sets the horizontal axis text style.
setXAxisTitle(title) ColumnChartBuilder Adds a title to the horizontal axis.
setXAxisTitleTextStyle(textStyle) ColumnChartBuilder Sets the horizontal axis title text style.
setYAxisTextStyle(textStyle) ColumnChartBuilder Sets the vertical axis text style.
setYAxisTitle(title) ColumnChartBuilder Adds a title to the vertical axis.
setYAxisTitleTextStyle(textStyle) ColumnChartBuilder Sets the vertical axis title text style.
useLogScale() ColumnChartBuilder Makes the range axis into a logarithmic scale (requires all values to be positive).

ColumnType

Properties

Property Type Description
DATE Enum Corresponds to date values.
NUMBER Enum Corresponds to number values.
STRING Enum Corresponds to string values.

CurveStyle

Properties

Property Type Description
NORMAL Enum Straight lines without curve.
SMOOTH Enum The angles of the line are smoothed.

DataTable

DataTableBuilder

Methods

Method Return type Brief description
addColumn(type, label) DataTableBuilder Adds a column to the data table.
addRow(values) DataTableBuilder Adds a row to the data table.
build() DataTable Builds and returns a data table.
setValue(row, column, value) DataTableBuilder Sets a specific value in the table.

DataTableSource

Methods

Method Return type Brief description
getDataTable() DataTable Return the data inside this object as a DataTable.

DataViewDefinition

DataViewDefinitionBuilder

Methods

Method Return type Brief description
build() DataViewDefinition Builds and returns the data view definition object that was built using this builder.
setColumns(columns) DataViewDefinitionBuilder Sets the indexes of the columns to include in the data view as well as specifying role-column information.

LineChartBuilder

Methods

Method Return type Brief description
build() Chart Builds the chart.
reverseCategories() LineChartBuilder Reverses the drawing of series in the domain axis.
setBackgroundColor(cssValue) LineChartBuilder Sets the background color for the chart.
setColors(cssValues) LineChartBuilder Sets the colors for the lines in the chart.
setCurveStyle(style) LineChartBuilder Sets the style to use for curves in the chart.
setDataSourceUrl(url) LineChartBuilder Sets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder) LineChartBuilder Sets the data table to use for the chart using a DataTableBuilder.
setDataTable(table) LineChartBuilder Sets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition) LineChartBuilder Sets the data view definition to use for the chart.
setDimensions(width, height) LineChartBuilder Sets the dimensions for the chart.
setLegendPosition(position) LineChartBuilder Sets the position of the legend with respect to the chart.
setLegendTextStyle(textStyle) LineChartBuilder Sets the text style of the chart legend.
setOption(option, value) LineChartBuilder Sets advanced options for this chart.
setPointStyle(style) LineChartBuilder Sets the style for points in the line.
setRange(start, end) LineChartBuilder Sets the range for the chart.
setTitle(chartTitle) LineChartBuilder Sets the title of the chart.
setTitleTextStyle(textStyle) LineChartBuilder Sets the text style of the chart title.
setXAxisTextStyle(textStyle) LineChartBuilder Sets the horizontal axis text style.
setXAxisTitle(title) LineChartBuilder Adds a title to the horizontal axis.
setXAxisTitleTextStyle(textStyle) LineChartBuilder Sets the horizontal axis title text style.
setYAxisTextStyle(textStyle) LineChartBuilder Sets the vertical axis text style.
setYAxisTitle(title) LineChartBuilder Adds a title to the vertical axis.
setYAxisTitleTextStyle(textStyle) LineChartBuilder Sets the vertical axis title text style.
useLogScale() LineChartBuilder Makes the range axis into a logarithmic scale (requires all values to be positive).

MatchType

Properties

Property Type Description
EXACT Enum Match exact values only
PREFIX Enum Match prefixes starting from the beginning of the value
ANY Enum Match any substring

Methods

Method Return type Brief description
getName() String Returns the name of the match type to be used in the options JSON.

NumberRangeFilterBuilder

Methods

Method Return type Brief description
setMaxValue(maxValue) NumberRangeFilterBuilder Sets the maximum allowed value for the range lower extent.
setMinValue(minValue) NumberRangeFilterBuilder Sets the minimum allowed value for the range lower extent.
setOrientation(orientation) NumberRangeFilterBuilder Sets the slider orientation.
setShowRangeValues(showRangeValues) NumberRangeFilterBuilder Sets whether to have labels next to the slider displaying extents of the selected range.
setTicks(ticks) NumberRangeFilterBuilder Sets the number of ticks (fixed positions in a range bar) a number range filter slider thumbs can fall in.

Orientation

Properties

Property Type Description
HORIZONTAL Enum Horizontal orientation.
VERTICAL Enum Vertical orientation.

PickerValuesLayout

Properties

Property Type Description
ASIDE Enum Selected values display in a single text line next to the value picker widget.
BELOW Enum Selected values display in a single text line below the widget.
BELOW_WRAPPING Enum Similar to below, but entries that cannot fit in the picker wrap to a new line.
BELOW_STACKED Enum Selected values display in a column below the widget.

PieChartBuilder

Methods

Method Return type Brief description
build() Chart Builds the chart.
reverseCategories() PieChartBuilder Reverses the drawing of series in the domain axis.
set3D() PieChartBuilder Sets the chart to be three-dimensional.
setBackgroundColor(cssValue) PieChartBuilder Sets the background color for the chart.
setColors(cssValues) PieChartBuilder Sets the colors for the lines in the chart.
setDataSourceUrl(url) PieChartBuilder Sets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder) PieChartBuilder Sets the data table to use for the chart using a DataTableBuilder.
setDataTable(table) PieChartBuilder Sets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition) PieChartBuilder Sets the data view definition to use for the chart.
setDimensions(width, height) PieChartBuilder Sets the dimensions for the chart.
setLegendPosition(position) PieChartBuilder Sets the position of the legend with respect to the chart.
setLegendTextStyle(textStyle) PieChartBuilder Sets the text style of the chart legend.
setOption(option, value) PieChartBuilder Sets advanced options for this chart.
setTitle(chartTitle) PieChartBuilder Sets the title of the chart.
setTitleTextStyle(textStyle) PieChartBuilder Sets the text style of the chart title.

PointStyle

Properties

Property Type Description
NONE Enum Do not display line points.
TINY Enum Use tiny line points.
MEDIUM Enum Use medium sized line points.
LARGE Enum Use large sized line points.
HUGE Enum Use largest sized line points.

Position

Properties

Property Type Description
TOP Enum Above the chart.
RIGHT Enum To the right of the chart.
BOTTOM Enum Below the chart.
NONE Enum No legend is displayed.

ScatterChartBuilder

Methods

Method Return type Brief description
build() Chart Builds the chart.
setBackgroundColor(cssValue) ScatterChartBuilder Sets the background color for the chart.
setColors(cssValues) ScatterChartBuilder Sets the colors for the lines in the chart.
setDataSourceUrl(url) ScatterChartBuilder Sets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder) ScatterChartBuilder Sets the data table to use for the chart using a DataTableBuilder.
setDataTable(table) ScatterChartBuilder Sets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition) ScatterChartBuilder Sets the data view definition to use for the chart.
setDimensions(width, height) ScatterChartBuilder Sets the dimensions for the chart.
setLegendPosition(position) ScatterChartBuilder Sets the position of the legend with respect to the chart.
setLegendTextStyle(textStyle) ScatterChartBuilder Sets the text style of the chart legend.
setOption(option, value) ScatterChartBuilder Sets advanced options for this chart.
setPointStyle(style) ScatterChartBuilder Sets the style for points in the line.
setTitle(chartTitle) ScatterChartBuilder Sets the title of the chart.
setTitleTextStyle(textStyle) ScatterChartBuilder Sets the text style of the chart title.
setXAxisLogScale() ScatterChartBuilder Makes the horizontal axis into a logarithmic scale (requires all values to be positive).
setXAxisRange(start, end) ScatterChartBuilder Sets the range for the horizontal axis of the chart.
setXAxisTextStyle(textStyle) ScatterChartBuilder Sets the horizontal axis text style.
setXAxisTitle(title) ScatterChartBuilder Adds a title to the horizontal axis.
setXAxisTitleTextStyle(textStyle) ScatterChartBuilder Sets the horizontal axis title text style.
setYAxisLogScale() ScatterChartBuilder Makes the vertical axis into a logarithmic scale (requires all values to be positive).
setYAxisRange(start, end) ScatterChartBuilder Sets the range for the vertical axis of the chart.
setYAxisTextStyle(textStyle) ScatterChartBuilder Sets the vertical axis text style.
setYAxisTitle(title) ScatterChartBuilder Adds a title to the vertical axis.
setYAxisTitleTextStyle(textStyle) ScatterChartBuilder Sets the vertical axis title text style.

StringFilterBuilder

Methods

Method Return type Brief description
setCaseSensitive(caseSensitive) StringFilterBuilder Sets whether matching should be case sensitive or not.
setMatchType(matchType) StringFilterBuilder Sets whether the control should match exact values only (MatchType.EXACT), prefixes starting from the beginning of the value (MatchType.PREFIX), or any substring (MatchType.ANY).
setRealtimeTrigger(realtimeTrigger) StringFilterBuilder Sets whether the control should match any time a key is pressed or only when the input field 'changes' (loss of focus or pressing the Enter key).

TableChartBuilder

Methods

Method Return type Brief description
build() Chart Builds the chart.
enablePaging(enablePaging) TableChartBuilder Sets whether to enable paging through the data.
enablePaging(pageSize) TableChartBuilder Enables paging and sets the number of rows in each page.
enablePaging(pageSize, startPage) TableChartBuilder Enables paging, sets the number of rows in each page and the first table page to display (page numbers are zero based).
enableRtlTable(rtlEnabled) TableChartBuilder Adds basic support for right-to-left languages (such as Arabic or Hebrew) by reversing the column order of the table, so that column zero is the right-most column, and the last column is the left-most column.
enableSorting(enableSorting) TableChartBuilder Sets whether to sort columns when the user clicks a column heading.
setDataSourceUrl(url) TableChartBuilder Sets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder) TableChartBuilder Sets the data table to use for the chart using a DataTableBuilder.
setDataTable(table) TableChartBuilder Sets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition) TableChartBuilder Sets the data view definition to use for the chart.
setDimensions(width, height) TableChartBuilder Sets the dimensions for the chart.
setFirstRowNumber(number) TableChartBuilder Sets the row number for the first row in the data table.
setInitialSortingAscending(column) TableChartBuilder Sets the index of the column according to which the table should be initially sorted (ascending).
setInitialSortingDescending(column) TableChartBuilder Sets the index of the column according to which the table should be initially sorted (descending).
setOption(option, value) TableChartBuilder Sets advanced options for this chart.
showRowNumberColumn(showRowNumber) TableChartBuilder Sets whether to show the row number as the first column of the table.
useAlternatingRowStyle(alternate) TableChartBuilder Sets whether alternating color style is assigned to odd and even rows of a table chart.

TextStyle

Methods

Method Return type Brief description
getColor() String Gets the color of the text style.
getFontName() String Gets the font name of the text style.
getFontSize() Number Gets the font size of the text style.

TextStyleBuilder

Methods

Method Return type Brief description
build() TextStyle Builds and returns a text style configuration object that was built using this builder.
setColor(cssValue) TextStyleBuilder Sets the color of the text style.
setFontName(fontName) TextStyleBuilder Sets the font name of the text style
setFontSize(fontSize) TextStyleBuilder Sets the font size of the text style.