Class EmbeddedTableChartBuilder

EmbeddedTableChartBuilder

Builder for table charts. For more details, see the Gviz documentation.

Methods

MethodReturn typeBrief description
addRange(range)EmbeddedChartBuilderAdds a Range to the chart represented by this builder.
asAreaChart()EmbeddedAreaChartBuilderSets the chart type to AreaChart and returns an EmbeddedAreaChartBuilder.
asBarChart()EmbeddedBarChartBuilderSets the chart type to BarChart and returns an EmbeddedBarChartBuilder.
asColumnChart()EmbeddedColumnChartBuilderSets the chart type to ColumnChart and returns an EmbeddedColumnChartBuilder.
asComboChart()EmbeddedComboChartBuilderSets the chart type to ComboChart and returns an EmbeddedComboChartBuilder.
asHistogramChart()EmbeddedHistogramChartBuilderSets the chart type to HistogramChart and returns an EmbeddedHistogramChartBuilder.
asLineChart()EmbeddedLineChartBuilderSets the chart type to LineChart and returns an EmbeddedLineChartBuilder.
asPieChart()EmbeddedPieChartBuilderSets the chart type to PieChart and returns an EmbeddedPieChartBuilder.
asScatterChart()EmbeddedScatterChartBuilderSets the chart type to ScatterChart and returns an EmbeddedScatterChartBuilder.
asTableChart()EmbeddedTableChartBuilderSets the chart type to TableChart and returns an EmbeddedTableChartBuilder.
build()EmbeddedChartBuilds the chart to reflect all changes made to it.
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 (page numbers are zero based).
enableRtlTable(rtlEnabled)EmbeddedTableChartBuilderAdds 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)EmbeddedTableChartBuilderSets whether to sort columns when the user clicks a column heading.
getChartType()ChartTypeReturns the current chart type.
getContainer()ContainerInfoReturn the ContainerInfo, which encapsulates where the chart appears on the sheet.
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 represented by this builder.
setChartType(type)EmbeddedChartBuilderChanges the type of chart.
setFirstRowNumber(number)EmbeddedTableChartBuilderSets the row number for the first row in the data table.
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).
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.
showRowNumberColumn(showRowNumber)EmbeddedTableChartBuilderSets whether to show the row number as the first column of the table.
useAlternatingRowStyle(alternate)EmbeddedTableChartBuilderSets whether alternating color style will be assigned to odd and even rows of a table chart.

Detailed documentation

addRange(range)

Adds a Range to the chart represented by this builder. Will not add the Range if it has already been added to the chart.


 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var chart = 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 — the builder for method chaining


asAreaChart()

Sets the chart type to AreaChart and returns an EmbeddedAreaChartBuilder.

Return

EmbeddedAreaChartBuilder — a builder for an area chart


asBarChart()

Sets the chart type to BarChart and returns an EmbeddedBarChartBuilder.

Return

EmbeddedBarChartBuilder — a builder for a bar chart


asColumnChart()

Sets the chart type to ColumnChart and returns an EmbeddedColumnChartBuilder.

Return

EmbeddedColumnChartBuilder — a builder for a column chart


asComboChart()

Sets the chart type to ComboChart and returns an EmbeddedComboChartBuilder.

Return

EmbeddedComboChartBuilder — a builder for a combo chart


asHistogramChart()

Sets the chart type to HistogramChart and returns an EmbeddedHistogramChartBuilder.

Return

EmbeddedHistogramChartBuilder — a builder for a histogram chart


asLineChart()

Sets the chart type to LineChart and returns an EmbeddedLineChartBuilder.

Return

EmbeddedLineChartBuilder — a builder for a line chart


asPieChart()

Sets the chart type to PieChart and returns an EmbeddedPieChartBuilder.

Return

EmbeddedPieChartBuilder — a builder for a pie chart


asScatterChart()

Sets the chart type to ScatterChart and returns an EmbeddedScatterChartBuilder.

Return

EmbeddedScatterChartBuilder — a builder for a scatter chart


asTableChart()

Sets the chart type to TableChart and returns an EmbeddedTableChartBuilder.

Return

EmbeddedTableChartBuilder — a builder for a table chart


build()

Builds the chart to reflect all changes made to it.

This method will not automatically draw the chart on top of the spreadsheet. A new chart must be inserted via sheet.insertChart(chart), and an existing chart should be updated via sheet.updateChart(chart);


 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var range = sheet.getRange("A1:B5");
 var chart = 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


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.
 var builder = 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 (page numbers 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.
 var builder = 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 the column order of the table, so that column zero is the right-most column, and the last column is the 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 even with this option. This option will be ignored if you enable paging (using the page option), or if the table has scroll bars because you have specified height and width options smaller than the required 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 will be automatically sorted. The default behavior is sorting enabled.

Parameters

NameTypeDescription
enableSortingBooleantrue if 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 ContainerInfo, which encapsulates where the chart appears on the sheet.


 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var chartBuilder = 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()
 var containerInfo = chartBuilder.getContainer();

 // Logs the values we 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. Use addRange and removeRange to modify this list.


 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var chartBuilder = sheet.newChart()
     .setChartType(Charts.ChartType.BAR)
     .addRange(sheet.getRange("A1:B8"))
     .setPosition(5, 5, 0, 0)

 var ranges = chartBuilder.getRanges();

 // There's only one range as a data source for this chart,
 // so this logs "A1:B8"
 for (var i in ranges) {
   var range = 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 represented by this builder. Will not throw an error if the Range is not in this chart.

The range removed must match up with a range added via addRange(range), or it will not be removed, and it will not throw an exception. This method cannot be used to partially remove values from a range.


 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var firstRange = sheet.getRange("A1:B5");
 var secondRange = sheet.getRange("A6:B8");

 var chartBuilder = sheet.newChart()
     .setChartType(Charts.ChartType.BAR)
     .addRange(firstRange)
     // This range will render 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
 // will not be removed, and will not throw an exception
 chartBuilder.removeRange(firstRange);
 chartBuilder.removeRange(sheet.getRange("A6:B8"));

 var chart = chartBuilder.build();

 sheet.insertChart(chart);
 

Parameters

NameTypeDescription
rangeRangethe range to remove

Return

EmbeddedChartBuilder — the builder for method chaining


setChartType(type)

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


 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var range = sheet.getRange("A1:B5");
 var chart = sheet.newChart()
     .setChartType(Charts.ChartType.BAR)
     .addRange(range)
     .setPosition(5, 5, 0, 0)
     .build()

 sheet.insertChart(chart);
 

Parameters

NameTypeDescription
typeChartTypea chart type

Return

EmbeddedChartBuilder — the builder for method 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.
 var builder = 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


setInitialSortingAscending(column)

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

The column will be sorted in ascending order and will be marked with a small arrow indicating that.


 // Creates a table chart builder and sorts it by the second column (ascending).
 var builder = 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 will be sorted in descending order and be marked with a a small arrow indicating that.


 // Creates a table chart builder and sorts it by the second column (descending).
 var builder = 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


setOption(option, value)

Sets advanced options for this chart. Lookup the chart type in the Charts API Chart Gallery for a listing of the available options. For example, the options for an area chart are listed here.

This method will NOT validate the option you specify is valid for this chart type nor if the value is of the correct format/structure.

This example shows how to change the animation duration to 1 second and set a legend.


 builder.setOption('title', 'Earnings projections');
 builder.setOption('animation.duration', 1000);
 builder.setOption('legend', {position: 'top', textStyle: {color: 'blue', fontSize: 16}});
 

Parameters

NameTypeDescription
optionStringthe name of the option
valueObjectthe value of the option

Return

EmbeddedChartBuilder — the builder for method chaining


setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)

Sets the position, changing where the chart appears on the sheet. AnchorRowPos and AnchorColPos are 1-indexed.


 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

 var range = sheet.getRange("A1:B5");
 var chart = sheet.newChart()
     .setChartType(Charts.ChartType.BAR)
     .addRange(range)
     .setPosition(5, 5, 0, 0)
     .build()

 sheet.insertChart(chart);
 

Parameters

NameTypeDescription
anchorRowPosIntegerthe chart's top side will be anchored in this row
anchorColPosIntegerthe chart's left side will be anchored in this column
offsetXIntegerthe chart's upper right-hand corner will be offset by this many pixels
offsetYIntegerthe chart's lower left-hand corner will be offset by this many pixels

Return

EmbeddedChartBuilder — the builder for method 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 will be 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

Send feedback about...

Apps Script
Apps Script