▾
Relationship between average U.S. SAT scores and earnings.
What is a scatterplot?
Scatterplots are used to display the relationship between two numeric variables. The x-axis typically represents one numeric variable, while the y-axis represents another numeric variable.
Data configurations
This section covers a few data configuration examples for scatterplots, each configured using the scatterplot model. See the scatterplot model reference for the full list of available properties and methods.
With numeric fields
With two numeric fields, one specified via the xAxisField property and the other specified via the yAxisField property, a basic scatterplot can visualize the relationship between these two variables.
Each point on the chart represents a data record, with its position determined by the values of the x and y fields.
- Set the
xAxisFieldproperty to"SAT_Score_Average"and theyAxisFieldproperty to"Earnings", which are both integer fields.
29 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Scatterplot</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "fcf794778a4d486eb0ce863ab71d40db", }, }); const chartElement = document.querySelector("arcgis-chart"); const scatterplotModel = await createModel({ layer: featureLayer, chartType: "scatterplot" }); scatterplotModel.xAxisField = "SAT_Score_Average"; scatterplotModel.yAxisField = "Earnings";5 collapsed lines
chartElement.model = scatterplotModel; chartElement.actionMode = "none"; </script> </body></html>Customization options
Bubble plot
Scatterplot can also be configured with a third numeric field, or commonly known as a bubble plot. Allowing you to to visualize the size of each point based on the values of the third field.
- Set the
sizePolicyproperty to an object withtypeset to"sizeScale",scaleTypeset to"linear",fieldset to"TUITIONFEE", and specify theminSizeandmaxSizefor the points.
31 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Bubble plot</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "fcf794778a4d486eb0ce863ab71d40db", }, }); const chartElement = document.querySelector("arcgis-chart"); const scatterplotModel = await createModel({ layer: featureLayer, chartType: "scatterplot" }); scatterplotModel.xAxisField = "SAT_Score_Average"; scatterplotModel.yAxisField = "Earnings"; scatterplotModel.sizePolicy = { type: "sizeScale", scaleType: "linear", field: "TUITIONFEE", minSize: 5, maxSize: 20, };5 collapsed lines
chartElement.model = scatterplotModel; chartElement.actionMode = "none"; </script> </body></html>Linear trend line
A regression equation is calculated and the associated linear trend line and R-squared value can be displayed on the scatterplot. The trend line models the linear relationship between the x and y fields, while the R-squared value indicates how well the trend line fits the data. A sloping upward trend line indicates a positive correlation, meaning that as the x values increase, the y values also tend to increase. A sloping downward trend line indicates a negative correlation, meaning that as the x values increase, the y values tend to decrease.
- Set the
showLinearTrendproperty totrueto display the linear trend line and R-squared value on the scatterplot. - Use the
linearTrendSymbolproperty to customize the appearance of the linear trend line by providing a symbol object.
31 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Scatterplot with linear trend</title> <style> html, body, arcgis-chart { height: 100%; margin: 0; } </style> <!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.2/"></script> </head>
<body> <arcgis-chart></arcgis-chart> <script type="module"> const { createModel } = await $arcgis.import("@arcgis/charts-components/model/shared/setup-utils.js"); const FeatureLayer = await $arcgis.import("@arcgis/core/layers/FeatureLayer.js"); const featureLayer = new FeatureLayer({ portalItem: { id: "fcf794778a4d486eb0ce863ab71d40db", }, }); const chartElement = document.querySelector("arcgis-chart"); const scatterplotModel = await createModel({ layer: featureLayer, chartType: "scatterplot" }); scatterplotModel.xAxisField = "SAT_Score_Average"; scatterplotModel.yAxisField = "Earnings"; scatterplotModel.showLinearTrend = true; scatterplotModel.linearTrendSymbol = { type: "esriSLS", style: "esriSLSDashDotDot", color: [255, 0, 0, 100], width: 4, };5 collapsed lines
chartElement.model = scatterplotModel; chartElement.actionMode = "none"; </script> </body></html>