CodePen
Sandbox Download

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.

CodePen
Sandbox Download
This chart visualizes the distribution of SAT scores, with each bin representing a range of scores. The height of each bin reflects the count of students within that score range.
  1. Set the numericField property to "SAT_Score_Average" to specify the numeric field.
With 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.
CodePen
Sandbox Download
The income field in this dataset has a positively skewed distribution, which contains a few large values that can make it difficult to visualize the distribution of the data. By applying a logarithmic transformation to the income field, we can compress the scale of the data and make it easier to see the distribution of the values, especially for the smaller values.
  1. Set the dataTransformationType property to "logarithmic" to apply a logarithmic transformation.
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.
CodePen
Sandbox Download
This histogram includes overlay lines for various descriptive statistics, such as the normal distribution, mean, median, and standard deviation, to help visualize and analyze the data distribution.
  1. Set the showMeanOverlay, showMedianOverlay, showNormalDistOverlay and showStandardDevOverlay properties to true to display the overlays.
  2. Set the normalDistSymbol property to customize the appearance of the normal distribution curve. Similar customizations can be made for the other overlays using the meanSymbol, medianSymbol and standardDevSymbol properties.
Overlays
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.

CodePen
Sandbox Download
This histogram allows customization of the number of bins and their appearance to better analyze the data distribution.
  1. Use the binCount property to set the number of bins in the histogram.
  2. Use the binSymbol property to customize the appearance of the bins in the histogram.
Bins
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>