Skip to content

This sample demonstrates how to create a histogram range slider from the Histogram and Slider components and use it to filter a layer’s features based on a numeric attribute. The histogram can be generated with the histogram() statistics function.

const field = "temp";
const min = 0;
const max = 30;
// create the histogram for the temperature field
const histogramResponse = await histogram({
layer: layer,
field: field,
numBins: 100,
minValue: min,
maxValue: max,
});

Then you can construct the histogram using the output bins, and min/max values.

// set the histogram properties
histogramElement.bins = histogramResponse.bins;
histogramElement.min = min;
histogramElement.max = max;
histogramElement.colorStops = [
{
color: [89, 157, 212],
minValue: min,
maxValue: max,
},
];
// when the slider values change, update the histogram and apply a feature effect
sliderElement.addEventListener("arcgisInput", (event) => {
histogramElement.colorStops = [
{
color: [89, 157, 212],
minValue: sliderElement.values[0],
maxValue: sliderElement.values[1],
},
];
layerView.filter = {
where: `temp BETWEEN ${sliderElement.values[0]} AND ${sliderElement.values[1]}`,
};
});