ui.Chart.setChartType

  • Chart.setChartType sets the chart type of a ui.Chart instance.

  • This method returns the ui.Chart instance, allowing for method chaining.

  • The chartType argument is a String specifying the desired chart type, such as 'ScatterChart', 'LineChart', or 'ColumnChart'.

  • A variety of chart types can be set using this method, including Scatter, Line, Column, Bar, Pie, Area, and Table charts.

Sets the chartType of this chart.

Returns this chart.

UsageReturns
Chart.setChartType(chartType)ui.Chart
ArgumentTypeDetails
this: ui.chartui.ChartThe ui.Chart instance.
chartTypeStringThe chart type; e.g 'ScatterChart', 'LineChart', and 'ColumnChart'. For the complete list of charts, see: https://developers.google.com/chart/interactive/docs/gallery

Examples

Code Editor (JavaScript)

// A data table of population for selected states.
var dataTable = [
  [{role: 'domain', label: 'State'}, {role: 'data', label: 'Population'}],
  ['CA', 37253956],
  ['NY', 19378102],
  ['IL', 12830632],
  ['MI', 9883640],
  ['OR', 3831074],
];

// Chart the data using accepted chart types.
print('Scatter chart', ui.Chart(dataTable).setChartType('ScatterChart'));
print('Line chart', ui.Chart(dataTable).setChartType('LineChart'));
print('Column chart', ui.Chart(dataTable).setChartType('ColumnChart'));
print('Bar chart', ui.Chart(dataTable).setChartType('BarChart'));
print('Pie chart', ui.Chart(dataTable).setChartType('PieChart'));
print('Area chart', ui.Chart(dataTable).setChartType('AreaChart'));
print('Table', ui.Chart(dataTable).setChartType('Table'));