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

NameBrief description
AreaChartBuilderBuilder for area charts.
BarChartBuilderBuilder for bar charts.
ChartA Chart object, which can be converted to a static image.
ChartHiddenDimensionStrategyAn enumeration of how hidden dimensions in a source are expressed in a chart.
ChartMergeStrategyAn enumeration of how multiple ranges in the source are expressed in a chart.
ChartOptionsExposes options currently configured for a Chart, such as height, color, etc.
ChartTypeChart types supported by the Charts service.
ChartsEntry point for creating Charts in scripts.
ColumnChartBuilderBuilder for column charts.
ColumnTypeAn enumeration of the valid data types for columns in a DataTable.
CurveStyleAn enumeration of the styles for curves in a chart.
DataTableA Data Table to be used in charts.
DataTableBuilderBuilder of DataTable objects.
DataTableSourceInterface for objects that can represent their data as a DataTable.
DataViewDefinitionA data view definition for visualizing chart data.
DataViewDefinitionBuilderBuilder for DataViewDefinition objects.
LineChartBuilderBuilder for line charts.
MatchTypeAn enumeration of how a string value should be matched.
NumberRangeFilterBuilderA builder for number range filter controls.
OrientationAn enumeration of the orientation of an object.
PickerValuesLayoutAn enumeration of how to display selected values in picker widget.
PieChartBuilderA builder for pie charts.
PointStyleAn enumeration of the styles of points in a line.
PositionAn enumeration of legend positions within a chart.
ScatterChartBuilderBuilder for scatter charts.
StringFilterBuilderA builder for string filter controls.
TableChartBuilderA builder for table charts.
TextStyleA text style configuration object.
TextStyleBuilderA builder used to create TextStyle objects.

AreaChartBuilder

Methods

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

BarChartBuilder

Methods

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

Chart

Methods

MethodReturn typeBrief description
getAs(contentType)BlobReturn the data inside this object as a blob converted to the specified content type.
getBlob()BlobReturn the data inside this object as a blob.
getOptions()ChartOptionsReturns the options for this chart, such as height, colors, and axes.

ChartHiddenDimensionStrategy

Properties

PropertyTypeDescription
IGNORE_BOTHEnumDefault; charts skips any hidden columns and hidden rows.
IGNORE_ROWSEnumCharts skips hidden rows only.
IGNORE_COLUMNSEnumCharts skips hidden columns only.
SHOW_BOTHEnumCharts does not skip hidden columns or hidden rows.

ChartMergeStrategy

Properties

PropertyTypeDescription
MERGE_COLUMNSEnumDefault.
MERGE_ROWSEnumCharts merges the rows of multiple ranges.

ChartOptions

Methods

MethodReturn typeBrief description
get(option)ObjectReturns a configured option for this chart.
getOrDefault(option)ObjectReturns a configured option for this chart.

ChartType

Properties

PropertyTypeDescription
TIMELINEEnumTimeline chart.
AREAEnumArea chart
BAREnumBar chart
BUBBLEEnumBubble chart.
CANDLESTICKEnumCandlestick chart.
COLUMNEnumColumn chart
COMBOEnumCombo chart
GAUGEEnumGauge chart.
GEOEnumGeo chart.
HISTOGRAMEnumHistogram
RADAREnumRadar chart.
LINEEnumLine chart
ORGEnumOrg chart.
PIEEnumPie chart
SCATTEREnumScatter chart
SPARKLINEEnumSparkline chart.
STEPPED_AREAEnumStepped area chart.
TABLEEnumTable chart
TREEMAPEnumTreemap chart.
WATERFALLEnumWaterfall chart.

Charts

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 a DataTable.
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 the Google Chart Tools documentation.
newBarChart()BarChartBuilderStarts building a bar chart, as described in the Google Chart Tools documentation.
newColumnChart()ColumnChartBuilderStarts building a column chart, as described in the Google Chart Tools 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 the Google Chart Tools documentation.
newPieChart()PieChartBuilderStarts building a pie chart, as described in the Google Chart Tools documentation.
newScatterChart()ScatterChartBuilderStarts building a scatter chart, as described in the Google Chart Tools documentation.
newTableChart()TableChartBuilderStarts building a table chart, as described in the Google Chart Tools documentation.
newTextStyle()TextStyleBuilderCreates a new text style builder.

ColumnChartBuilder

Methods

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

ColumnType

Properties

PropertyTypeDescription
DATEEnumCorresponds to date values.
NUMBEREnumCorresponds to number values.
STRINGEnumCorresponds to string values.

CurveStyle

Properties

PropertyTypeDescription
NORMALEnumStraight lines without curve.
SMOOTHEnumThe angles of the line are smoothed.

DataTable

DataTableBuilder

Methods

MethodReturn typeBrief description
addColumn(type, label)DataTableBuilderAdds a column to the data table.
addRow(values)DataTableBuilderAdds a row to the data table.
build()DataTableBuilds and returns a data table.
setValue(row, column, value)DataTableBuilderSets a specific value in the table.

DataTableSource

Methods

MethodReturn typeBrief description
getDataTable()DataTableReturn the data inside this object as a DataTable.

DataViewDefinition

DataViewDefinitionBuilder

Methods

MethodReturn typeBrief description
build()DataViewDefinitionBuilds and returns the data view definition object that was built using this builder.
setColumns(columns)DataViewDefinitionBuilderSets the indexes of the columns to include in the data view as well as specifying role-column information.

LineChartBuilder

Methods

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

MatchType

Properties

PropertyTypeDescription
EXACTEnumMatch exact values only
PREFIXEnumMatch prefixes starting from the beginning of the value
ANYEnumMatch any substring

Methods

MethodReturn typeBrief description
getName()StringReturns the name of the match type to be used in the options JSON.

NumberRangeFilterBuilder

Methods

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

Orientation

Properties

PropertyTypeDescription
HORIZONTALEnumHorizontal orientation.
VERTICALEnumVertical orientation.

PickerValuesLayout

Properties

PropertyTypeDescription
ASIDEEnumSelected values display in a single text line next to the value picker widget.
BELOWEnumSelected values display in a single text line below the widget.
BELOW_WRAPPINGEnumSimilar to below, but entries that cannot fit in the picker wrap to a new line.
BELOW_STACKEDEnumSelected values display in a column below the widget.

PieChartBuilder

Methods

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

PointStyle

Properties

PropertyTypeDescription
NONEEnumDo not display line points.
TINYEnumUse tiny line points.
MEDIUMEnumUse medium sized line points.
LARGEEnumUse large sized line points.
HUGEEnumUse largest sized line points.

Position

Properties

PropertyTypeDescription
TOPEnumAbove the chart.
RIGHTEnumTo the right of the chart.
BOTTOMEnumBelow the chart.
NONEEnumNo legend is displayed.

ScatterChartBuilder

Methods

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

StringFilterBuilder

Methods

MethodReturn typeBrief description
setCaseSensitive(caseSensitive)StringFilterBuilderSets whether matching should be case sensitive or not.
setMatchType(matchType)StringFilterBuilderSets 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)StringFilterBuilderSets 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

MethodReturn typeBrief description
build()ChartBuilds the chart.
enablePaging(enablePaging)TableChartBuilderSets whether to enable paging through the data.
enablePaging(pageSize)TableChartBuilderEnables paging and sets the number of rows in each page.
enablePaging(pageSize, startPage)TableChartBuilderEnables paging, sets the number of rows in each page and the first table page to display (page numbers are zero based).
enableRtlTable(rtlEnabled)TableChartBuilderAdds 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)TableChartBuilderSets whether to sort columns when the user clicks a column heading.
setDataSourceUrl(url)TableChartBuilderSets the data source URL that is used to pull data in from an external source, such as Google Sheets.
setDataTable(tableBuilder)TableChartBuilderSets the data table to use for the chart using a DataTableBuilder.
setDataTable(table)TableChartBuilderSets the data table which contains the lines for the chart, as well as the X-axis labels.
setDataViewDefinition(dataViewDefinition)TableChartBuilderSets the data view definition to use for the chart.
setDimensions(width, height)TableChartBuilderSets the dimensions for the chart.
setFirstRowNumber(number)TableChartBuilderSets the row number for the first row in the data table.
setInitialSortingAscending(column)TableChartBuilderSets the index of the column according to which the table should be initially sorted (ascending).
setInitialSortingDescending(column)TableChartBuilderSets the index of the column according to which the table should be initially sorted (descending).
setOption(option, value)TableChartBuilderSets advanced options for this chart.
showRowNumberColumn(showRowNumber)TableChartBuilderSets whether to show the row number as the first column of the table.
useAlternatingRowStyle(alternate)TableChartBuilderSets whether alternating color style is assigned to odd and even rows of a table chart.

TextStyle

Methods

MethodReturn typeBrief description
getColor()StringGets the color of the text style.
getFontName()StringGets the font name of the text style.
getFontSize()NumberGets the font size of the text style.

TextStyleBuilder

Methods

MethodReturn typeBrief description
build()TextStyleBuilds and returns a text style configuration object that was built using this builder.
setColor(cssValue)TextStyleBuilderSets the color of the text style.
setFontName(fontName)TextStyleBuilderSets the font name of the text style
setFontSize(fontSize)TextStyleBuilderSets the font size of the text style.