Class ScatterChartBuilder Stay organized with collections Save and categorize content based on your preferences.
AI-generated Key Takeaways
ScatterChartBuilder is used to create scatter charts.
Data for the scatter chart can be imported from external sources like Google Spreadsheets using
setDataSourceUrl().You can customize various aspects of the chart using methods like
setTitle(),setXAxisTitle(),setYAxisTitle(), andsetDimensions().The
build()method is used to generate the final Chart object.
Builder for scatter charts. For more details, see theGoogle Charts documentation.
Here is an example that shows how to build a scatter chart. The data isimported from a Google spreadsheet.
// Get sample data from a spreadsheet.constdataSourceUrl='https://docs.google.com/spreadsheet/tq?range=C1%3AD'+'&key=0Aq4s9w_HxMs7dHpfX05JdmVSb1FpT21sbXd4NVE3UEE&gid=4&headers=-1';constchartBuilder=Charts.newScatterChart().setTitle('Adjusted GDP & U.S. Population').setXAxisTitle('U.S. Population (millions)').setYAxisTitle('Adjusted GDP ($ billions)').setDimensions(600,500).setLegendPosition(Charts.Position.NONE).setDataSourceUrl(dataSourceUrl);constchart=chartBuilder.build();
Methods
| Method | Return type | Brief description |
|---|---|---|
build() | Chart | Builds the chart. |
set | Scatter | Sets the background color for the chart. |
set | Scatter | Sets the colors for the lines in the chart. |
set | Scatter | Sets the data source URL that is used to pull data in from an external source, such as GoogleSheets. |
set | Scatter | Sets the data table to use for the chart using a DataTableBuilder. |
set | Scatter | Sets the data table which contains the lines for the chart, as well as the X-axis labels. |
set | Scatter | Sets the data view definition to use for the chart. |
set | Scatter | Sets the dimensions for the chart. |
set | Scatter | Sets the position of the legend with respect to the chart. |
set | Scatter | Sets the text style of the chart legend. |
set | Scatter | Sets advanced options for this chart. |
set | Scatter | Sets the style for points in the line. |
set | Scatter | Sets the title of the chart. |
set | Scatter | Sets the text style of the chart title. |
set | Scatter | Makes the horizontal axis into a logarithmic scale (requires all values to be positive). |
set | Scatter | Sets the range for the horizontal axis of the chart. |
set | Scatter | Sets the horizontal axis text style. |
set | Scatter | Adds a title to the horizontal axis. |
set | Scatter | Sets the horizontal axis title text style. |
set | Scatter | Makes the vertical axis into a logarithmic scale (requires all values to be positive). |
set | Scatter | Sets the range for the vertical axis of the chart. |
set | Scatter | Sets the vertical axis text style. |
set | Scatter | Adds a title to the vertical axis. |
set | Scatter | Sets the vertical axis title text style. |
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.
setBackgroundColor(cssValue)
Sets the background color for the chart.
// Creates a line chart builder and sets the background color to grayconstbuilder=Charts.newLineChart();builder.setBackgroundColor('gray');
Parameters
| Name | Type | Description |
|---|---|---|
css | String | The CSS value for the color (such as"blue" or"#00f"). |
Return
Scatter — This builder, useful for chaining.
setColors(cssValues)
Sets the colors for the lines in the chart.
// Creates a line chart builder and sets the first two lines to be drawn in// green and red, respectively.constbuilder=Charts.newLineChart();builder.setColors(['green','red']);
Parameters
| Name | Type | Description |
|---|---|---|
css | String[] | An array of color CSS values, such as["red", "#acf"]. The nth element in the array represents the color of the nth line in the chart. |
Return
Scatter — 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 GoogleSheets. 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 theGoogle Charts documentation.
Parameters
| Name | Type | Description |
|---|---|---|
url | String | The data source URL, including any query parameters. |
Return
Scatter — This builder, useful for chaining.
setDataTable(tableBuilder)
Sets the data table to use for the chart using a DataTableBuilder. This is a convenience methodfor setting the data table without needing to callbuild().
Parameters
| Name | Type | Description |
|---|---|---|
table | Data | A 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
Scatter — 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. Thefirst column should be a string, and contain the horizontal axis labels. Any number of columnscan follow, all must be numeric. Each column is displayed as a separate line.
Parameters
| Name | Type | Description |
|---|---|---|
table | Data | The data table to use for the chart. |
Return
Scatter — This builder, useful for chaining.
setDataViewDefinition(dataViewDefinition)
Sets the data view definition to use for the chart.
Parameters
| Name | Type | Description |
|---|---|---|
data | Data | A data view definition object that defines the view that should be derived from the given data source for the chart drawing. |
Return
Scatter — This builder, useful for chaining.
setDimensions(width, height)
Sets the dimensions for the chart.
Parameters
| Name | Type | Description |
|---|---|---|
width | Integer | The width of the chart, in pixels. |
height | Integer | The height of the chart, in pixels. |
Return
Scatter — This builder, useful for chaining.
setLegendPosition(position)
Sets the position of the legend with respect to the chart. By default, there is no legend.
// Creates a line chart builder and sets the legend position to right.constbuilder=Charts.newLineChart();builder.setLegendPosition(Charts.Position.RIGHT);
Parameters
| Name | Type | Description |
|---|---|---|
position | Position | The position of the legend. |
Return
Scatter — This builder, useful for chaining.
setLegendTextStyle(textStyle)
Sets the text style of the chart legend.
// Creates a line chart builder and sets it up for a blue, 26-point legend.consttextStyleBuilder=Charts.newTextStyle().setColor('#0000FF').setFontSize(26);conststyle=textStyleBuilder.build();constbuilder=Charts.newLineChart();builder.setLegendTextStyle(style);
Parameters
| Name | Type | Description |
|---|---|---|
text | Text | The text style to use for the chart legend. |
Return
Scatter — This builder, useful for chaining.
setOption(option, value)
Sets advanced options for this chart. Seethe available options forthis chart. This method has no effect if the given option is invalid.
// Build a scatter chart with a 1-second animation duration.constbuilder=Charts.newScatterChart();builder.setOption('animation.duration',1000);constchart=builder.build();
Parameters
| Name | Type | Description |
|---|---|---|
option | String | The option to set. |
value | Object | The value to set. |
Return
Scatter — This builder, useful for chaining.
setPointStyle(style)
Sets the style for points in the line. By default, points have no particular styles, and onlythe line is visible.
// Creates a line chart builder and sets large point style.constbuilder=Charts.newLineChart();builder.setPointStyle(Charts.PointStyle.LARGE);
Parameters
| Name | Type | Description |
|---|---|---|
style | Point | The style to use for points in the line. |
Return
Scatter — This builder, useful for chaining.
See also
setTitle(chartTitle)
Sets the title of the chart. The title is displayed centered above the chart.
// Creates a line chart builder and title to 'My Line Chart'.constbuilder=Charts.newLineChart();builder.setTitle('My Line Chart');
Parameters
| Name | Type | Description |
|---|---|---|
chart | String | the chart title. |
Return
Scatter — This builder, useful for chaining.
setTitleTextStyle(textStyle)
Sets the text style of the chart title.
// Creates a line chart builder and sets it up for a blue, 26-point title.consttextStyleBuilder=Charts.newTextStyle().setColor('#0000FF').setFontSize(26);conststyle=textStyleBuilder.build();constbuilder=Charts.newLineChart();builder.setTitleTextStyle(style);
Parameters
| Name | Type | Description |
|---|---|---|
text | Text | The text style to use for the chart title. You can create aText object by callingCharts.newTextStyle(). |
Return
Scatter — This builder, useful for chaining.
setXAxisLogScale()
Makes the horizontal axis into a logarithmic scale (requires all values to be positive).
Return
Scatter — This builder, useful for chaining.
setXAxisRange(start, end)
Sets the range for the horizontal axis of the chart.
If any data points fall outside the range, the range is expanded to include those datapoints.
// Creates a scatter chart builder and sets the X-axis range to be 0 to 100.constbuilder=Charts.newTableChart();builder.setXAxisRange(0,100);
Parameters
| Name | Type | Description |
|---|---|---|
start | Number | The value for the lowest grid line of the horizontal axis. |
end | Number | The value for the highest grid line of the horizontal axis. |
Return
Scatter — This builder, useful for chaining.
setXAxisTextStyle(textStyle)
Sets the horizontal axis text style.
// Creates a line chart builder and sets the X-axis text style to blue, 18-point// font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setXAxisTextStyle(textStyle);
Parameters
| Name | Type | Description |
|---|---|---|
text | Text | The text style to use for the horizontal axis title. You can create aText object by callingCharts.newTextStyle(). |
Return
Scatter — This builder, useful for chaining.
setXAxisTitle(title)
Adds a title to the horizontal axis. The title is centered and appears below the axis valuelabels.
// Creates a line chart builder and sets the X-axis title.constbuilder=Charts.newLineChart();builder.setTitle('X-axis Title');
Parameters
| Name | Type | Description |
|---|---|---|
title | String | The title for the X-axis. |
Return
Scatter — This builder, useful for chaining.
setXAxisTitleTextStyle(textStyle)
Sets the horizontal axis title text style.
// Creates a line chart builder and sets the X-axis title text style to blue,// 18-point font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setXAxisTitleTextStyle(textStyle);
Parameters
| Name | Type | Description |
|---|---|---|
text | Text | The text style to use for the horizontal axis title. You can create aText object by callingCharts.newTextStyle(). |
Return
Scatter — This builder, useful for chaining.
setYAxisLogScale()
Makes the vertical axis into a logarithmic scale (requires all values to be positive).
Return
Scatter — This builder, useful for chaining.
setYAxisRange(start, end)
Sets the range for the vertical axis of the chart. If any data points fall outside the range,the range is expanded to include those data points.
// Creates a scatter chart builder and sets the Y-axis range to be 0 to 100.constbuilder=Charts.newTableChart();builder.setYAxisRange(0,100);
Parameters
| Name | Type | Description |
|---|---|---|
start | Number | The value for the lowest grid line of the vertical axis. |
end | Number | The value for the highest grid line of the vertical axis. |
Return
Scatter — This builder, useful for chaining.
setYAxisTextStyle(textStyle)
Sets the vertical axis text style.
// Creates a line chart builder and sets the Y-axis text style to blue, 18-point// font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setYAxisTextStyle(textStyle);
Parameters
| Name | Type | Description |
|---|---|---|
text | Text | The text style to use for the horizontal axis title. You can create aText object by callingCharts.newTextStyle(). |
Return
Scatter — This builder, useful for chaining.
setYAxisTitle(title)
Adds a title to the vertical axis. The title is centered and appears to the left of the valuelabels.
// Creates a line chart builder and sets the Y-axis title.constbuilder=Charts.newLineChart();builder.setYAxisTitle('Y-axis Title');
Parameters
| Name | Type | Description |
|---|---|---|
title | String | The title for the Y-axis. |
Return
Scatter — This builder, useful for chaining.
setYAxisTitleTextStyle(textStyle)
Sets the vertical axis title text style.
// Creates a line chart builder and sets the Y-axis title text style to blue,// 18-point font.consttextStyle=Charts.newTextStyle().setColor('blue').setFontSize(18).build();constbuilder=Charts.newLineChart();builder.setYAxisTitleTextStyle(textStyle);
Parameters
| Name | Type | Description |
|---|---|---|
text | Text | The text style to use for the horizontal axis title. You can create aText object by callingCharts.newTextStyle(). |
Return
Scatter — 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-05-08 UTC.