Google Apps Script

Class TableChartBuilder

A builder for table charts. For more details, see the Google Charts documentation.

Here is an example that shows how to build a table chart. The data is imported from a Google spreadsheet.

 
function doGet() {
   // Get sample data from a spreadsheet.
   var dataSourceUrl = 'https://docs.google.com/spreadsheet/tq?range=A1%3AF' +
       '&key=0Aq4s9w_HxMs7dHpfX05JdmVSb1FpT21sbXd4NVE3UEE&gid=4&headers=-1';
   
   var chartBuilder = Charts.newTableChart()
       .setDimensions(600, 500)
       .enablePaging(20)
       .setDataSourceUrl(dataSourceUrl);
   
   var chart = chartBuilder.build();
   return UiApp.createApplication().add(chart);
 }
 

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 will be 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)TableChartBuilder

Sets 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 will be assigned to odd and even rows of a table chart.

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


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

TableChartBuilder — 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

TableChartBuilder — 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

TableChartBuilder — 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

TableChartBuilder — 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

TableChartBuilder — this builder, useful for chaining


setDataSourceUrl(url)

Sets the data source URL that will be used to pull data in from an external source, such as Google Sheets. 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 the Google Charts documentation.

Parameters

NameTypeDescription
urlStringthe data source URL, including any query parameters

Return

TableChartBuilder — this builder, useful for chaining


setDataTable(tableBuilder)

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

Parameters

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

Return

TableChartBuilder — 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. The first column should be a string, and contain the horizontal axis labels. Any number of columns can follow, all must be numeric. Each column is displayed as a separate line.

Parameters

NameTypeDescription
tableDataTableSourcethe data table to use for the chart

Return

TableChartBuilder — 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

TableChartBuilder — 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

TableChartBuilder — this builder, useful 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.
 var builder = Charts.newTableChart();
 builder.setFirstRowNumber(2);
 

Parameters

NameTypeDescription
numberIntegerthe row number for the first row in the data table

Return

TableChartBuilder — 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

TableChartBuilder — 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

TableChartBuilder — this builder, useful for chaining


setOption(option, value)

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

 
// Build a table chart which renders HTML.
 var builder = Charts.newTableChart();
 builder.setOption('allowHtml', true); 
 var chart = builder.build();
 

Parameters

NameTypeDescription
optionStringthe option to set
valueObjectthe value to set

Return

TableChartBuilder — this builder, useful 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

TableChartBuilder — 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

TableChartBuilder — this builder, useful for chaining

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.