Class TableChartBuilder

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.

// Get sample data from a spreadsheet.
const dataSourceUrl = 'https://docs.google.com/spreadsheet/tq?range=A1%3AF' +
    '&key=0Aq4s9w_HxMs7dHpfX05JdmVSb1FpT21sbXd4NVE3UEE&gid=4&headers=-1';

const chartBuilder = Charts.newTableChart()
                         .setDimensions(600, 500)
                         .enablePaging(20)
                         .setDataSourceUrl(dataSourceUrl);

const chart = chartBuilder.build();

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.

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.
const 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.
const 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 is 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 are automatically sorted. The default behavior is sorting enabled.

Parameters

NameTypeDescription
enableSortingBooleantrue 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 is 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 is 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.
const 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 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).
const 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 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).
const 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.
const builder = Charts.newTableChart();
builder.setOption('allowHtml', {@code true});
const 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 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

TableChartBuilder — This builder, useful for chaining.