Class ColumnChartBuilder

  • ColumnChartBuilder is a builder for creating column charts.

  • You can set data using a DataTable or a data source URL.

  • The builder provides methods to customize chart appearance, including title, axis titles, dimensions, colors, and background.

  • You can set advanced options using thesetOption method.

  • Thebuild() method returns a Chart object that can be used or embedded.

ColumnChartBuilder

Builder for column charts. For more details, see theGoogle Charts documentation.

This example shows how to create a column chart with data from a data table.

constsampleData=Charts.newDataTable().addColumn(Charts.ColumnType.STRING,'Year').addColumn(Charts.ColumnType.NUMBER,'Sales').addColumn(Charts.ColumnType.NUMBER,'Expenses').addRow(['2004',1000,400]).addRow(['2005',1170,460]).addRow(['2006',660,1120]).addRow(['2007',1030,540]).addRow(['2008',800,600]).addRow(['2009',943,678]).addRow(['2010',1020,550]).addRow(['2011',910,700]).addRow(['2012',1230,840]).build();constchart=Charts.newColumnChart().setTitle('Sales & Expenses').setXAxisTitle('Year').setYAxisTitle('Amount (USD)').setDimensions(600,500).setDataTable(sampleData).build();

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 GoogleSheets.
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).

Detailed documentation

build()

Builds the chart.

Return

Chart — A Chart object, which can be embedded into documents, UI elements, or used as a static image.


reverseCategories()

Reverses the drawing of series in the domain axis. For vertical-range charts (such as line,area or column charts), this means the horizontal axis is drawn from right to left. Forhorizontal-range charts (such as bar charts), this means the vertical axis is drawn from top tobottom. For pie charts, this means the slices are drawn counterclockwise.

// Creates a pie chart builder and sets drawing of the slices in a// counter-clockwise manner.constbuilder=Charts.newPieChart();builder.reverseCategories();

Return

ColumnChartBuilder — This builder, useful for chaining.


setBackgroundColor(cssValue)

Sets the background color for the chart.

// Creates a line chart builder and sets the background color to grayconstbuilder=Charts.newLineChart();builder.setBackgroundColor('gray');

Parameters

NameTypeDescription
cssValueStringThe CSS value for the color (such as"blue" or"#00f").

Return

ColumnChartBuilder — This builder, useful for chaining.


setColors(cssValues)

Sets the colors for the lines in the chart.

// Creates a line chart builder and sets the first two lines to be drawn in// green and red, respectively.constbuilder=Charts.newLineChart();builder.setColors(['green','red']);

Parameters

NameTypeDescription
cssValuesString[]An array of color CSS values, such as["red", "#acf"]. The nth element in the array represents the color of the nth line in the chart.

Return

ColumnChartBuilder — This builder, useful for chaining.


setDataSourceUrl(url)

Sets the data source URL that is used to pull data in from an external source, such as GoogleSheets. If a data source URL and a DataTable are provided, the data source URL is ignored.

For more information about querying data sources, check out theGoogle Charts documentation.

Parameters

NameTypeDescription
urlStringThe data source URL, including any query parameters.

Return

ColumnChartBuilder — This builder, useful for chaining.


setDataTable(tableBuilder)

Sets the data table to use for the chart using a DataTableBuilder. This is a convenience methodfor setting the data table without needing to callbuild().

Parameters

NameTypeDescription
tableBuilderDataTableBuilderA data table builder. A new data table is created instantly as part of this call, so any further updates to the builder won't be reflected in the chart.

Return

ColumnChartBuilder — This builder, useful for chaining.


setDataTable(table)

Sets the data table which contains the lines for the chart, as well as the X-axis labels. Thefirst column should be a string, and contain the horizontal axis labels. Any number of columnscan follow, all must be numeric. Each column is displayed as a separate line.

Parameters

NameTypeDescription
tableDataTableSourceThe data table to use for the chart.

Return

ColumnChartBuilder — This builder, useful for chaining.


setDataViewDefinition(dataViewDefinition)

Sets the data view definition to use for the chart.

Parameters

NameTypeDescription
dataViewDefinitionDataViewDefinitionA data view definition object that defines the view that should be derived from the given data source for the chart drawing.

Return

ColumnChartBuilder — This builder, useful for chaining.


setDimensions(width, height)

Sets the dimensions for the chart.

Parameters

NameTypeDescription
widthIntegerThe width of the chart, in pixels.
heightIntegerThe height of the chart, in pixels.

Return

ColumnChartBuilder — This builder, useful for chaining.


setLegendPosition(position)

Sets the position of the legend with respect to the chart. By default, there is no legend.

// Creates a line chart builder and sets the legend position to right.constbuilder=Charts.newLineChart();builder.setLegendPosition(Charts.Position.RIGHT);

Parameters

NameTypeDescription
positionPositionThe position of the legend.

Return

ColumnChartBuilder — This builder, useful for chaining.


setLegendTextStyle(textStyle)

Sets the text style of the chart legend.

// Creates a line chart builder and sets it up for a  blue, 26-point legend.consttextStyleBuilder=Charts.newTextStyle().setColor('#0000FF').setFontSize(26);conststyle=textStyleBuilder.build();constbuilder=Charts.newLineChart();builder.setLegendTextStyle(style);

Parameters

NameTypeDescription
textStyleTextStyleThe text style to use for the chart legend.

Return

ColumnChartBuilder — This builder, useful for chaining.


setOption(option, value)

Sets advanced options for this chart. Seethe available options forthis chart. This method has no effect if the given option is invalid.

// Build a column chart with a 1-second animation duration.constbuilder=Charts.newColumnChart();builder.setOption('animation.duration',1000);constchart=builder.build();

Parameters

NameTypeDescription
optionStringThe option to set.
valueObjectThe value to set.

Return

ColumnChartBuilder — This builder, useful for chaining.


setRange(start, end)

Sets the range for the chart.

If any data points fall outside the range, the range is expanded to include those datapoints.

Parameters

NameTypeDescription
startNumberThe value for the lowest grid line of the range axis.
endNumberThe value for the highest grid line of the range axis.

Return

ColumnChartBuilder — This builder, useful for chaining.


setStacked()

Uses stacked lines, meaning that line and bar values are stacked (accumulated). By default,there is no stacking.

Return

ColumnChartBuilder — This builder, useful for chaining.


setTitle(chartTitle)

Sets the title of the chart. The title is displayed centered above the chart.

// Creates a line chart builder and title to 'My Line Chart'.constbuilder=Charts.newLineChart();builder.setTitle('My Line Chart');

Parameters

NameTypeDescription
chartTitleStringthe chart title.

Return

ColumnChartBuilder — This builder, useful for chaining.


setTitleTextStyle(textStyle)

Sets the text style of the chart title.

// Creates a line chart builder and sets it up for a  blue, 26-point title.consttextStyleBuilder=Charts.newTextStyle().setColor('#0000FF').setFontSize(26);conststyle=textStyleBuilder.build();constbuilder=Charts.newLineChart();builder.setTitleTextStyle(style);

Parameters

NameTypeDescription
textStyleTextStyleThe text style to use for the chart title. You can create aTextStyleBuilder object by callingCharts.newTextStyle().

Return

ColumnChartBuilder — This builder, useful for chaining.


setXAxisTextStyle(textStyle)

Sets the horizontal axis text style.

// Creates a line chart builder and sets the X-axis text style to blue, 18-point// font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setXAxisTextStyle(textStyle);

Parameters

NameTypeDescription
textStyleTextStyleThe text style to use for the horizontal axis title. You can create aTextStyleBuilder object by callingCharts.newTextStyle().

Return

ColumnChartBuilder — This builder, useful for chaining.


setXAxisTitle(title)

Adds a title to the horizontal axis. The title is centered and appears below the axis valuelabels.

// Creates a line chart builder and sets the X-axis title.constbuilder=Charts.newLineChart();builder.setTitle('X-axis Title');

Parameters

NameTypeDescription
titleStringThe title for the X-axis.

Return

ColumnChartBuilder — This builder, useful for chaining.


setXAxisTitleTextStyle(textStyle)

Sets the horizontal axis title text style.

// Creates a line chart builder and sets the X-axis title text style to blue,// 18-point font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setXAxisTitleTextStyle(textStyle);

Parameters

NameTypeDescription
textStyleTextStyleThe text style to use for the horizontal axis title. You can create aTextStyleBuilder object by callingCharts.newTextStyle().

Return

ColumnChartBuilder — This builder, useful for chaining.


setYAxisTextStyle(textStyle)

Sets the vertical axis text style.

// Creates a line chart builder and sets the Y-axis text style to blue, 18-point// font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setYAxisTextStyle(textStyle);

Parameters

NameTypeDescription
textStyleTextStyleThe text style to use for the horizontal axis title. You can create aTextStyleBuilder object by callingCharts.newTextStyle().

Return

ColumnChartBuilder — This builder, useful for chaining.


setYAxisTitle(title)

Adds a title to the vertical axis. The title is centered and appears to the left of the valuelabels.

// Creates a line chart builder and sets the Y-axis title.constbuilder=Charts.newLineChart();builder.setYAxisTitle('Y-axis Title');

Parameters

NameTypeDescription
titleStringThe title for the Y-axis.

Return

ColumnChartBuilder — This builder, useful for chaining.


setYAxisTitleTextStyle(textStyle)

Sets the vertical axis title text style.

// Creates a line chart builder and sets the Y-axis title text style to blue,// 18-point font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setYAxisTitleTextStyle(textStyle);

Parameters

NameTypeDescription
textStyleTextStyleThe text style to use for the horizontal axis title. You can create aTextStyleBuilder object by callingCharts.newTextStyle().

Return

ColumnChartBuilder — This builder, useful for chaining.


useLogScale()

Makes the range axis into a logarithmic scale (requires all values to be positive). The rangeaxis are the vertical axis for vertical charts (such as line, area, or column) and thehorizontal axis for horizontal charts (such as bar).

Return

ColumnChartBuilder — This builder, useful for chaining.

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.