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 demonstrates how different data configurations can be used to create various types of histograms.

With numeric field

Histogram with a numeric field groups data into bins based on the values of a numeric variable.

The above 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.
Charts component
30 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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";
14 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.

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.
Charts component
31 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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";
7 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.
  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.
Charts component
31 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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,
};
14 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, this can be customized by using the binCount property.

Additionally, the binSymbol property allows you to control the appearance of the bins in the histogram.

Charts component
31 collapsed lines
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Esri Developer Guide: 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.1/"></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],
};
14 collapsed lines
histogramModel.setAxisValueFormat(0, {
type: "number",
intlOptions: {
style: "decimal",
minimumFractionDigits: 0,
maximumFractionDigits: 0,
},
});
chartElement.model = histogramModel;
chartElement.actionMode = "none";
</script>
</body>
</html>