Class EmbeddedTableChartBuilder

  • EmbeddedTableChartBuilder is a builder specifically for table charts, offering various methods to configure their appearance and behavior.

  • You can add or remove data ranges, set the chart type to other embedded chart types, and build the chart with thebuild() method.

  • Key table-specific options include enabling paging and sorting, setting the first row number, enabling right-to-left support, showing row numbers, and using alternating row styles.

  • Additional methods allow setting advanced chart options, the position of the chart on the sheet, the merge strategy for multiple ranges, and the strategy for hidden dimensions.

  • You can also retrieve information about the chart's current type, container, and data ranges.

EmbeddedTableChartBuilder

Builder for table charts. For more details, see the Gvizdocumentation.

Methods

MethodReturn typeBrief description
addRange(range)EmbeddedChartBuilderAdds a range to the chart this builder modifies.
asAreaChart()EmbeddedAreaChartBuilderSets the chart type to AreaChart and returns anEmbeddedAreaChartBuilder.
asBarChart()EmbeddedBarChartBuilderSets the chart type to BarChart and returns anEmbeddedBarChartBuilder.
asColumnChart()EmbeddedColumnChartBuilderSets the chart type to ColumnChart and returns anEmbeddedColumnChartBuilder.
asComboChart()EmbeddedComboChartBuilderSets the chart type to ComboChart and returns anEmbeddedComboChartBuilder.
asHistogramChart()EmbeddedHistogramChartBuilderSets the chart type to HistogramChart and returns anEmbeddedHistogramChartBuilder.
asLineChart()EmbeddedLineChartBuilderSets the chart type to LineChart and returns anEmbeddedLineChartBuilder.
asPieChart()EmbeddedPieChartBuilderSets the chart type to PieChart and returns anEmbeddedPieChartBuilder.
asScatterChart()EmbeddedScatterChartBuilderSets the chart type to ScatterChart and returns anEmbeddedScatterChartBuilder.
asTableChart()EmbeddedTableChartBuilderSets the chart type to TableChart and returns anEmbeddedTableChartBuilder.
build()EmbeddedChartBuilds the chart to reflect all changes made to it.
clearRanges()EmbeddedChartBuilderRemoves all ranges from the chart this builder modifies.
enablePaging(enablePaging)EmbeddedTableChartBuilderSets whether to enable paging through the data.
enablePaging(pageSize)EmbeddedTableChartBuilderEnables paging and sets the number of rows in each page.
enablePaging(pageSize, startPage)EmbeddedTableChartBuilderEnables paging, sets the number of rows in each page and the first table page to display (pagenumbers are zero based).
enableRtlTable(rtlEnabled)EmbeddedTableChartBuilderAdds basic support for right-to-left languages (such as Arabic or Hebrew) by reversing thecolumn order of the table, so that column zero is the right-most column, and the last column isthe left-most column.
enableSorting(enableSorting)EmbeddedTableChartBuilderSets whether to sort columns when the user clicks a column heading.
getChartType()ChartTypeReturns the current chart type.
getContainer()ContainerInfoReturn the chartContainerInfo, which encapsulates where the chart appears on thesheet.
getRanges()Range[]Returns a copy of the list of ranges currently providing data for this chart.
removeRange(range)EmbeddedChartBuilderRemoves the specified range from the chart this builder modifies.
setChartType(type)EmbeddedChartBuilderChanges the type of chart.
setFirstRowNumber(number)EmbeddedTableChartBuilderSets the row number for the first row in the data table.
setHiddenDimensionStrategy(strategy)EmbeddedChartBuilderSets the strategy to use for hidden rows and columns.
setInitialSortingAscending(column)EmbeddedTableChartBuilderSets the index of the column according to which the table should be initially sorted(ascending).
setInitialSortingDescending(column)EmbeddedTableChartBuilderSets the index of the column according to which the table should be initially sorted(descending).
setMergeStrategy(mergeStrategy)EmbeddedChartBuilderSets the merge strategy to use when more than one range exists.
setNumHeaders(headers)EmbeddedChartBuilderSets the number of rows or columns of the range that should be treated as headers.
setOption(option, value)EmbeddedChartBuilderSets advanced options for this chart.
setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)EmbeddedChartBuilderSets the position, changing where the chart appears on the sheet.
setTransposeRowsAndColumns(transpose)EmbeddedChartBuilderSets whether the chart's rows and columns are transposed.
showRowNumberColumn(showRowNumber)EmbeddedTableChartBuilderSets whether to show the row number as the first column of the table.
useAlternatingRowStyle(alternate)EmbeddedTableChartBuilderSets whether alternating color style is assigned to odd and even rows of a table chart.

Detailed documentation

addRange(range)

Adds a range to the chart this builder modifies. Does not add the range if it has already beenadded to the chart.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(sheet.getRange('A1:B8')).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Parameters

NameTypeDescription
rangeRangeThe range to add.

Return

EmbeddedChartBuilder — This builder, for chaining.


asAreaChart()

Sets the chart type to AreaChart and returns anEmbeddedAreaChartBuilder.

Return

EmbeddedAreaChartBuilder — A builder for an area chart.


asBarChart()

Sets the chart type to BarChart and returns anEmbeddedBarChartBuilder.

Return

EmbeddedBarChartBuilder — A builder for a bar chart.


asColumnChart()

Sets the chart type to ColumnChart and returns anEmbeddedColumnChartBuilder.

Return

EmbeddedColumnChartBuilder — A builder for a column chart.


asComboChart()

Sets the chart type to ComboChart and returns anEmbeddedComboChartBuilder.

Return

EmbeddedComboChartBuilder — A builder for a combo chart.


asHistogramChart()

Sets the chart type to HistogramChart and returns anEmbeddedHistogramChartBuilder.

Return

EmbeddedHistogramChartBuilder — A builder for a histogram chart.


asLineChart()

Sets the chart type to LineChart and returns anEmbeddedLineChartBuilder.

Return

EmbeddedLineChartBuilder — A builder for a line chart.


asPieChart()

Sets the chart type to PieChart and returns anEmbeddedPieChartBuilder.

Return

EmbeddedPieChartBuilder — A builder for a pie chart.


asScatterChart()

Sets the chart type to ScatterChart and returns anEmbeddedScatterChartBuilder.

Return

EmbeddedScatterChartBuilder — A builder for a scatter chart.


asTableChart()

Sets the chart type to TableChart and returns anEmbeddedTableChartBuilder.

Return

EmbeddedTableChartBuilder — A builder for a table chart.


build()

Builds the chart to reflect all changes made to it.

This method does not automatically draw the chart on top of the spreadsheet. A new chartmust be inserted viasheet.insertChart(chart), and an existing chart should be updatedviasheet.updateChart(chart).

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constrange=sheet.getRange('A1:B5');constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(range).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Return

EmbeddedChart — The created chart, which must still be added to the spreadsheet.


clearRanges()

Removes all ranges from the chart this builder modifies.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];// This code updates the chart to use only the new ranges while preserving the// existing formatting of the chart.constchart=sheet.getCharts()[0];constnewChart=chart.modify().clearRanges().addRange(sheet.getRange('A1:A5')).addRange(sheet.getRange('B1:B5')).build();sheet.updateChart(newChart);

Return

EmbeddedChartBuilder — This builder, for chaining.


enablePaging(enablePaging)

Sets whether to enable paging through the data.

The default behavior is paging disabled. If paging is enabled the default page size is 10.

Parameters

NameTypeDescription
enablePagingBooleantrue if paging should be enabled,false otherwise.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


enablePaging(pageSize)

Enables paging and sets the number of rows in each page.

The default page size is 10.

// Creates a table chart builder and enables paging with page size of 5.constbuilder=Charts.newTableChart();builder.enablePaging(5);

Parameters

NameTypeDescription
pageSizeIntegerThe number of rows in each page of the table.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


enablePaging(pageSize, startPage)

Enables paging, sets the number of rows in each page and the first table page to display (pagenumbers are zero based).

The default page size is 10, and the default start page is 0.

// Creates a table chart builder and enables paging with page size of 5 and// displays page 2 first.constbuilder=Charts.newTableChart();builder.enablePaging(5,2);

Parameters

NameTypeDescription
pageSizeIntegerThe number of rows in each page of the table.
startPageIntegerThe first table page to display (page numbers are zero-based).

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


enableRtlTable(rtlEnabled)

Adds basic support for right-to-left languages (such as Arabic or Hebrew) by reversing thecolumn order of the table, so that column zero is the right-most column, and the last column isthe left-most column.

This does not affect the column index in the underlying data, only the order of display.Full bi-directional (BiDi) language display is not supported by the table visualization evenwith this option. This option is ignored if you enable paging (using the page option), or ifthe table has scroll bars because you have specified height and width options smaller than therequired table size. The default behavior is RTL support disabled.

Parameters

NameTypeDescription
rtlEnabledBooleantrue if right-to-left support should be enabled,false otherwise.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


enableSorting(enableSorting)

Sets whether to sort columns when the user clicks a column heading.

If sorting is enabled, when users click on the column header the rows are automaticallysorted. The default behavior is sorting enabled.

Parameters

NameTypeDescription
enableSortingBooleantrue to enable sorting by clicking on column headers,false otherwise.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


getChartType()

Returns the current chart type.

Return

ChartType — The chart type.


getContainer()

Return the chartContainerInfo, which encapsulates where the chart appears on thesheet.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constchartBuilder=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(sheet.getRange('A1:B8')).setPosition(5,5,0,0);// This method returns the exact same data as Chart#getContainerInfo()constcontainerInfo=chartBuilder.getContainer();// Logs the values used in setPosition()Logger.log('Anchor Column: %s\r\nAnchor Row %s\r\nOffset X %s\r\nOffset Y %s',containerInfo.getAnchorColumn(),containerInfo.getAnchorRow(),containerInfo.getOffsetX(),containerInfo.getOffsetY(),);

Return

ContainerInfo — An object containing the chart container's position.


getRanges()

Returns a copy of the list of ranges currently providing data for this chart. UseaddRange(range) andremoveRange(range) to modify this list.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constchartBuilder=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(sheet.getRange('A1:B8')).setPosition(5,5,0,0);constranges=chartBuilder.getRanges();// There's only one range as a data source for this chart,// so this logs "A1:B8"for(constiinranges){constrange=ranges[i];Logger.log(range.getA1Notation());}

Return

Range[] — An array of ranges that serve as the chart to be built's data source.


removeRange(range)

Removes the specified range from the chart this builder modifies. Does not throw an error ifthe range is not in this chart.

The range removed must match up with a range added viaaddRange(range);otherwise no change is made to the chart. This method cannot be used to partially remove valuesfrom a range.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constfirstRange=sheet.getRange('A1:B5');constsecondRange=sheet.getRange('A6:B8');constchartBuilder=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(firstRange)// This range renders in a different color.addRange(secondRange).setPosition(5,5,0,0);// Note that you can use either of these two formats, but the range// MUST match up with a range that was added via addRange(), or it// is not removed, and does not throw an exceptionchartBuilder.removeRange(firstRange);chartBuilder.removeRange(sheet.getRange('A6:B8'));constchart=chartBuilder.build();sheet.insertChart(chart);

Parameters

NameTypeDescription
rangeRangeThe range to remove.

Return

EmbeddedChartBuilder — This builder, for chaining.


setChartType(type)

Changes the type of chart. Not all embedded chart types are currently supported. SeeChartType.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constrange=sheet.getRange('A1:B5');constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(range).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Parameters

NameTypeDescription
typeChartTypeThe type to change this chart into.

Return

EmbeddedChartBuilder — This builder, for chaining.


setFirstRowNumber(number)

Sets the row number for the first row in the data table.

The default row number of the first row is 1.

// Creates a table chart builder and sets the first row to be 2.constbuilder=Charts.newTableChart();builder.setFirstRowNumber(2);

Parameters

NameTypeDescription
numberIntegerThe row number for the first row in the data table.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


setHiddenDimensionStrategy(strategy)

Sets the strategy to use for hidden rows and columns. Defaults toIGNORE_ROWS.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constrange=sheet.getRange('A1:B5');constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(range).setHiddenDimensionStrategy(Charts.ChartHiddenDimensionStrategy.IGNORE_COLUMNS,).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Parameters

NameTypeDescription
strategyChartHiddenDimensionStrategyThe strategy to use for hidden rows and columns.

Return

EmbeddedChartBuilder — This builder, for chaining.


setInitialSortingAscending(column)

Sets the index of the column according to which the table should be initially sorted(ascending).

The column os sorted in ascending order and is marked with a small arrow indicating that.

// Creates a table chart builder and sorts it by the second column (ascending).constbuilder=Charts.newTableChart();builder.setInitialSortingAscending(2);

Parameters

NameTypeDescription
columnIntegerThe number of the column according to which the table should be initially sorted.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


setInitialSortingDescending(column)

Sets the index of the column according to which the table should be initially sorted(descending).

The column os sorted in descending order and is marked with a a small arrow indicating that.

// Creates a table chart builder and sorts it by the second column (descending).constbuilder=Charts.newTableChart();builder.setInitialSortingDescending(2);

Parameters

NameTypeDescription
columnIntegerThe number of the column according to which the table should be initially sorted.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


setMergeStrategy(mergeStrategy)

Sets the merge strategy to use when more than one range exists. IfMERGE_ROWS, rows are merged; ifMERGE_COLUMNS, columns are merged. Defaults toMERGE_COLUMNS.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constrange=sheet.getRange('A1:B10');constrange2=sheet.getRange('C:C10');constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(range).addRange(range2).setMergeStrategy(Charts.ChartMergeStrategy.MERGE_ROWS).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Parameters

NameTypeDescription
mergeStrategyChartMergeStrategyThe merge strategy to use.

Return

EmbeddedChartBuilder — This builder, for chaining.


setNumHeaders(headers)

Sets the number of rows or columns of the range that should be treated as headers.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constrange=sheet.getRange('A1:B5');constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(range).setNumHeaders(1).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Parameters

NameTypeDescription
headersIntegerThe number of rows or columns to treat as headers. Negative values cause headers to be auto-detected.

Return

EmbeddedChartBuilder — This builder, for chaining.


setOption(option, value)

Sets advanced options for this chart. To view a list of the available options, seeChartconfiguration options.

This method doesn't validate the option you specify is valid for this chart type nor if thevalue is of the correct format/structure.

This example shows how to change the title and set a legend.

constspreadsheet=SpreadsheetApp.getActiveSpreadsheet();constsheet=spreadsheet.getSheets()[0];constchart=sheet.newChart().setOption('title','Earnings projections').setOption('legend',{position:'top',textStyle:{color:'blue',fontSize:16},}).build();

Parameters

NameTypeDescription
optionStringThe name of the option.
valueObjectThe value of the option.

Return

EmbeddedChartBuilder — This builder, for chaining.


setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)

Sets the position, changing where the chart appears on the sheet.anchorRowPos andanchorColPos are 1-indexed.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constrange=sheet.getRange('A1:B5');constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(range).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Parameters

NameTypeDescription
anchorRowPosIntegerThe chart's top side is anchored in this row.
anchorColPosIntegerThe chart's left side is anchored in this column.
offsetXIntegerThe chart's upper right-hand corner is offset by this many pixels.
offsetYIntegerThe chart's lower left-hand corner is offset by this many pixels.

Return

EmbeddedChartBuilder — This builder, for chaining.


setTransposeRowsAndColumns(transpose)

Sets whether the chart's rows and columns are transposed. If set totrue, the rows andcolumns are switched. Defaults tofalse.

constss=SpreadsheetApp.getActiveSpreadsheet();constsheet=ss.getSheets()[0];constrange=sheet.getRange('A1:B5');constchart=sheet.newChart().setChartType(Charts.ChartType.BAR).addRange(range).setTransposeRowsAndColumns(true).setPosition(5,5,0,0).build();sheet.insertChart(chart);

Parameters

NameTypeDescription
transposeBooleanIftrue, the rows and columns used to construct the chart are transposed.

Return

EmbeddedChartBuilder — This builder, for chaining.


showRowNumberColumn(showRowNumber)

Sets whether to show the row number as the first column of the table.

The default behavior is not showing row numbers.

Parameters

NameTypeDescription
showRowNumberBooleantrue if the first column of the table should show the row number,false otherwise.

Return

EmbeddedTableChartBuilder — This builder, useful for chaining.


useAlternatingRowStyle(alternate)

Sets whether alternating color style is assigned to odd and even rows of a table chart.

The default behavior is the rows having alternating color style.

Parameters

NameTypeDescription
alternateBooleantrue if color styles should be alternating,false otherwise.

Return

EmbeddedTableChartBuilder — 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.