Skip to content

HistogramRangeSlider

This sample demonstrates how to create a HistogramRangeSlider widget and use it to filter a layer's features based on a numeric attribute. The histogram can be generated with the histogram() statistics function.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const layerView = await viewElement.whenLayerView(layer);
// temperature in Celsius
const field = "temp";
const min = 0;
const max = 30;

// generate 100-bin histogram
const histogramResponse = await histogram({
  layer: layer,
  field: field,
  numBins: 100,
  minValue: min,
  maxValue: max
});

Then you can construct the slider using the output bins, and min/max values. You also must indicate a rangeType. This property serves two purposes:

  1. It determines how histogram bars are rendered, indicating which bins are included and excluded from the selected range.
  2. It determines the SQL where clause used for executing queries, highlighting, selecting, or filtering features.

In this case, the rangeType is between so two thumbs will render on the slider track and all values between the two thumbs will be included in the selection/query/filter.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const slider = new HistogramRangeSlider({
  bins: histogramResponse.bins,
  min: min,
  max: max,
  values: [min, max],
  excludedBarColor: "#524e4e",
  rangeType: "between",
  container: document.getElementById("slider-container"),
});

slider.on(["thumb-change", "thumb-drag", "segment-drag"], (event) => {
  layerView.filter = {
    // generates the where clause for filtering features
    where: slider.generateWhereClause(field),
  };
});
Image preview of related sample Histogram widget

Histogram widget

Image preview of related sample Update a renderer's attribute

Update a renderer's attribute

Image preview of related sample Customize ColorSlider Histogram

Customize ColorSlider Histogram

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.