This sample visualizes cities in Mexico by population and demonstrates how to visualize the distribution of the data using a Histogram widget.
The histogram can be generated with the histogram() statistics function, then constructed with the fromHistogramResult() convenience method.
const params = {
layer: layer,
field: "pobtot",
numBins: 30
};
const histogramResult = await histogram(params);
// Creates a Histogram instance from the returned histogram result
const histogramWidget = Histogram.fromHistogramResult(
histogramResult
);
histogramWidget.container = "histogram";
You can also specify a normalization
to normalize skewed histograms. For example, a histogram representing a total count, such as population, will typically be skewed to the right.
![histogram-skew](/javascript/latest/static/338e65e5c8e42cb853112ed597befa81/e17e5/histogram-skew.png)
Normalizing the data by natural-log may help you work with and understand the data better.
![histogram-nl](/javascript/latest/static/1f615cb04ccae0bba0bb3c90719ff5bc/e17e5/histogram-nl.png)
The Histogram widget is also used in the smart mapping slider widgets. All the options available on a standalone histogram can also be set in the sliders. See the related samples below for more examples.