▾
Distribution of U.S. SAT scores.
What is a histogram?
Histograms are used to visualize the distribution of a single numeric field by grouping data into bins and displaying the frequency of data points within each bin. The x-axis represents the range of values divided into intervals (bins), while the y-axis represents the count or frequency of data points that fall within each bin.
Data configurations
This section covers an example for histograms, configured using the histogram model. See the histogram model reference for the full list of available properties and methods.
With numeric field
Histogram with a numeric field groups data into bins based on the values of a numeric variable.
- Set the
numericFieldproperty to"SAT_Score_Average"to specify the numeric field.
29 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Histogram</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 histogramModel = await createModel({ layer: featureLayer, chartType: "histogram" }); histogramModel.numericField = "SAT_Score_Average";13 collapsed lines
histogramModel.setAxisValueFormat(0, { type: "number", intlOptions: { style: "decimal", minimumFractionDigits: 0, maximumFractionDigits: 0, }, }); chartElement.model = histogramModel; chartElement.actionMode = "none"; </script> </body></html>Customization options
Transformation
There are two types of data transformations that can be applied to histograms:
- Logarithmic: When the data has a positively skewed distribution and there are a few large values, a logarithmic transformation can be applied to the data to compress the scale and make it easier to visualize and analyze. Can only be applied to numbers greater than zero.
- Square root: Similar to logarithmic transformation, a square root transformation can be applied to data with a skewed distribution. Can be applied to numbers greater than or equal to zero.
- Set the
dataTransformationTypeproperty to"logarithmic"to apply a logarithmic transformation.
30 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Histogram with Transformation</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: "c99e16e5573c47ab8c4536cb77673211", }, }); const chartElement = document.querySelector("arcgis-chart"); const histogramModel = await createModel({ layer: featureLayer, chartType: "histogram" }); histogramModel.numericField = "income_percap"; histogramModel.dataTransformationType = "logarithmic";6 collapsed lines
histogramModel.titleText = "Histogram with logarithmic transformation"; chartElement.model = histogramModel; chartElement.actionMode = "none"; </script> </body></html>Overlays
The following descriptive statistics can be calculated and displayed as overlay lines on the histogram:
- Normal distribution : A bell-shaped curve used to compare data to a normal distribution pattern.
- Mean: The average value of the data set, calculated by summing all values and dividing by the number of values.
- Median: The middle value of the data set when it is ordered from least to greatest.
- Standard deviation: Two vertical lines representing one standard deviation above and below the mean, indicating the spread of the data around the mean.
- Set the
showMeanOverlay,showMedianOverlay,showNormalDistOverlayandshowStandardDevOverlayproperties totrueto display the overlays. - Set the
normalDistSymbolproperty to customize the appearance of the normal distribution curve. Similar customizations can be made for the other overlays using themeanSymbol,medianSymbolandstandardDevSymbolproperties.
30 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Histogram with overlays</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 histogramModel = await createModel({ layer: featureLayer, chartType: "histogram" }); histogramModel.numericField = "SAT_Score_Average"; histogramModel.showMeanOverlay = true; histogramModel.showMedianOverlay = true; histogramModel.showNormalDistOverlay = true; histogramModel.showStandardDevOverlay = true; histogramModel.normalDistSymbol = { type: "esriSLS", style: "esriSLSDash", color: [255, 0, 0, 100], width: 4, };13 collapsed lines
histogramModel.setAxisValueFormat(0, { type: "number", intlOptions: { style: "decimal", minimumFractionDigits: 0, maximumFractionDigits: 0, }, }); chartElement.model = histogramModel; chartElement.actionMode = "none"; </script> </body></html>Bins
The default number of bins for a histogram is 32, the count and symbol can be further customized.
- Use the
binCountproperty to set the number of bins in the histogram. - Use the
binSymbolproperty to customize the appearance of the bins in the histogram.
30 collapsed lines
<html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>Histogram bins customization</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 histogramModel = await createModel({ layer: featureLayer, chartType: "histogram" }); histogramModel.numericField = "SAT_Score_Average"; histogramModel.binCount = 15; histogramModel.binSymbol = { style: "esriSFSForwardDiagonal", color: [210, 100, 110, 100], };13 collapsed lines
histogramModel.setAxisValueFormat(0, { type: "number", intlOptions: { style: "decimal", minimumFractionDigits: 0, maximumFractionDigits: 0, }, }); chartElement.model = histogramModel; chartElement.actionMode = "none"; </script> </body></html>