Skip To ContentArcGIS for DevelopersSign In Dashboard

HistogramRangeSlider

require(["esri/widgets/HistogramRangeSlider"], function(HistogramRangeSlider) { /* code goes here */ });
Class: esri/widgets/HistogramRangeSlider
Inheritance: HistogramRangeSlider Widget Accessor
Since: ArcGIS API for JavaScript 4.12

A slider widget that can be used for filtering data or gathering numeric input from a user for a range of data. When bins are provided, a histogram will render on the slider showing where data is distributed along the range. Use the rangeType property to indicate how the histogram should be styled as the user interacts with slider handles.

See the image below for a summary of the configurable options available on this slider.

HistogramRangeSlider with annotations

For information about gaining full control of widget styles, see the Styling topic.
See also:

Constructors

new HistogramRangeSlider(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Example:
// Typical usage
const slider = new HistogramRangeSlider({
  container: "sliderDiv",
  min: 0,
  max: 100,
  values: [ 50, 150 ]
});

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
Number

The statistical average of the data in the histogram.

more details
more detailsHistogramRangeSlider
BarCreatedFunction

Function for styling bars representing histogram bins.

more details
more detailsHistogramRangeSlider
Bin[]

An array of objects representing each bin in the histogram.

more details
more detailsHistogramRangeSlider
String|HTMLElement

The ID or node representing the DOM element containing the widget.

more details
more detailsWidget
DataLineCreatedFunction

Function that fires each time a data line is created.

more details
more detailsHistogramRangeSlider
Object[]

When set, renders lines on the histogram that indicate important or meaningful values to the end user.

more details
more detailsHistogramRangeSlider
String

The name of the class.

more details
more detailsAccessor
Boolean

When true, this property indicates whether the widget has been destroyed.

more details
more detailsWidget
Color

Sets the color of the histogram bars that are excluded based on the specified rangeType.

more details
more detailsHistogramRangeSlider
String

The unique ID assigned to the widget when the widget is created.

more details
more detailsWidget
Color

Sets the color of the histogram bars that are included in the specified rangeType.

more details
more detailsHistogramRangeSlider
String

The widget's default label.

more details
more detailsHistogramRangeSlider
LabelFormatter

A function used to format labels.

more details
more detailsHistogramRangeSlider
Number

The maximum value or upper bound of the slider.

more details
more detailsHistogramRangeSlider
Number

The minimum value or lower bound of the slider.

more details
more detailsHistogramRangeSlider
Number

Defines how slider thumb values should be rounded.

more details
more detailsHistogramRangeSlider
String

Indicates how the histogram bins should be rendered as the user slides the thumbs.

more details
more detailsHistogramRangeSlider
Number

Indicates the standard deviation of the dataset.

more details
more detailsHistogramRangeSlider
Number

Indicates the number of standard deviation lines to render on the histogram from the [average].

more details
more detailsHistogramRangeSlider
Number[]

An array of either one or two numbers representing thumb positions on the slider.

more details
more detailsHistogramRangeSlider
HistogramRangeSliderViewModel

The view model for the widget.

more details
more detailsHistogramRangeSlider

Property Details

average Number

The statistical average of the data in the histogram. You would typically get this value from the avg property of SummaryStatisticsResult, which is the result of the summaryStatistics function.

When set, this value will render on the histogram with a line and an average symbol.

Examples:
// sets result returned from a smart mapping method
// to the histogram
slider.average = response.statistics.avg;
slider.average = 34.5;
barCreatedFunction BarCreatedFunction

Function for styling bars representing histogram bins. This can be used to color bins with the same color of features in the view that fall into bins representing the same range of data.

Example:
slider.barCreatedFunction = function(index, element){
  const bin = slider.bins[index];
  element.addEventListener("focus", function(){
    layerView.filter = {
      where: `POPULATION >= ${bin.minValue} AND POPULATION < ${bin.maxValue}`
    };
  });
  element.addEventListener("blur", function(){
    layerView.filter = null;
  });
};
bins Bin[]

An array of objects representing each bin in the histogram. This information is typically returned from the histogram function.

Examples:
// sets the bins of the histogram from the bins in the histogram() result
histogram.bins = histogramResult.bins;
// Creates a histogram with 7 bins.
histogram.bins = [
  { minValue: 0, maxValue: 10, count: 4 },
  { minValue: 10.1, maxValue: 20, count: 14 },
  { minValue: 20.1, maxValue: 30, count: 9 },
  { minValue: 30.1, maxValue: 40, count: 34 },
  { minValue: 40.1, maxValue: 50, count: 351 },
  { minValue: 50.1, maxValue: 60, count: 100 },
  { minValue: 60.1, maxValue: 70, count: 1 }
];

The ID or node representing the DOM element containing the widget. This property can only be set once. The following examples are all valid use cases when working with widgets.

Examples:
// Create the HTML div element programmatically at runtime and set to the widget's container
const basemapGallery = new BasemapGallery({
  view: view,
  container: document.createElement("div")
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
// Specify an already-defined HTML div element in the widget's container

const basemapGallery = new BasemapGallery({
  view: view,
  container: basemapGalleryDiv
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});

// HTML markup
<body>
  <div id="viewDiv"></div>
  <div id="basemapGalleryDiv"></div>
</body>
// Specify the widget while adding to the view's UI
const basemapGallery = new BasemapGallery({
  view: view
});

// Add the widget to the top-right corner of the view
view.ui.add(basemapGallery, {
  position: "top-right"
});
dataLineCreatedFunction DataLineCreatedFunction

Function that fires each time a data line is created. You can use this to style individual dataLines on the data axis.

Example:
histogram.dataLineCreatedFunction = function (lineElement, labelElement) {
  lineElement.setAttribute("y2", "25%");
  lineElement.classList.add("line-style");
};
dataLines Object[]

When set, renders lines on the histogram that indicate important or meaningful values to the end user.

Properties:
value Number

The value on the data axis of the histogram where a line will be rendered.

optional

The label associated with the line.

Examples:
// will render lines at the 25th, 50th, 75th, and 99th percentiles
histogram.dataLines = [{
  value: 30,
  label: "25 pctl"
}, {
  value: 45,
  label: "50 pctl"
}, {
  value: 65,
  label: "75 pctl"
}, {
  value: 89,
  label: "99 pctl"
}];
// calculate standard deviations from mean using stats
// returned from smart mapping statistic methods
const stddevs = smartMappingUtils.getDeviationValues(stats.stddev, stats.avg, 2);
histogram.dataLines = stddevs.map(function(stddev){
  return {
    value: stddev
  };
});
declaredClass Stringreadonly inherited

The name of the class. The declared class name is formatted as esri.folder.className.

destroyed Boolean inherited

When true, this property indicates whether the widget has been destroyed.

excludedBarColor Colorautocast
Autocasts from Number[]|String|Object

Sets the color of the histogram bars that are excluded based on the specified rangeType. For example, when a rangeType of between is used, all bars not between the slider thumbs will be rendered with the color set here.

To change the style of histogram bars representing included data based on the rangeType, use the includedBarColor property.

Default Value:#d7e5f0
See also:
Example:
slider.excludedBarColor = "black";

The unique ID assigned to the widget when the widget is created. If not set by the developer, it will default to the container ID, or if that is not present then it will be automatically generated.

includedBarColor Colorautocast
Autocasts from Number[]|String|Object

Sets the color of the histogram bars that are included in the specified rangeType. For example, when a rangeType of between is used, all bars between the slider thumbs will be rendered with the color set here.

To change the style of histogram bars representing excluded data based on the rangeType, use the excludedBarColor property.

Default Value:#599dd4
See also:
Example:
slider.includedBarColor = "green";
label String

The widget's default label. This label displays when it is used within another widget, such as the Expand or LayerList widgets.

labelFormatFunction LabelFormatter

A function used to format labels. Overrides the default label formatter.

By default labels are formatted in the following way:

  • When the data range is less than 10 ((max - min) < 10), labels are rounded based on the value set in the precision property.
  • When the data range is larger than 10, labels display with a precision of no more than two decimal places, though actual slider thumb values will maintain the precision specified in precision.

Use this property to override the behavior defined above.

Examples:
// For thumb values, rounds each label to whole numbers.
// Note the actual value of the thumb continues to be stored
// based on the indicated data `precision` despite this formatting
slider.labelFormatFunction = function(value, type) {
  return (type === "value") ? value.toFixed(0) : value;
}
// Format thumb values as dates
slider.labelFormatFunction = function(value, type) {
  return new Date(value).toLocaleDateString();
}
max Number

The maximum value or upper bound of the slider. If the largest slider value in the constructor is greater than the maxValue set in this property, then the maxValue will update to match the largest slider value.

Example:
slider.max = 150;
min Number

The minimum value or lower bound of the slider. If the smallest slider value in the constructor is greater than the minValue set in this property, then the minValue will update to match the smallest slider value.

Example:
slider.min = -150;
precision Number

Defines how slider thumb values should be rounded. This number indicates the number of decimal places slider thumb values should round to when they have been moved.

This value also indicates the precision of thumb labels when the data range (max - min) is less than 10.

When the data range is larger than 10, labels display with a precision of no more than two decimal places, though actual slider thumb values will maintain the precision specified in this property.

For example, given the default precision of 4, and the following slider configuration, The label of the thumb will display two decimal places, but the precision of the actual thumb value will not be lost even when the user slides or moves the thumb.

const slider = new HistogramRangeSliderViewModel({
  min: 20,
  max: 100,  // data range of 80
  values: [50.4331],
  // thumb label will display 50.43
  // thumb value will maintain precision, so
  // value will remain at 50.4331
});

If the user manually enters a value that has a higher precision than what's indicated by this property, the precision of that thumb value will be maintained until the thumb is moved by the user. At that point, the value will be rounded according to the indicated precision.

Keep in mind this property rounds thumb values and shouldn't be used exclusively for formatting purposes. To format thumb labels, use the labelFormatFunction property.

Default Value:4
Example:
histogramRangeSlider.precision = 7;
rangeType String

Indicates how the histogram bins should be rendered as the user slides the thumbs. By default, blue bars indicate data bins included in the range. Gray bars indicate data bins excluded from the range. These colors can be customized with the includedBarColor and excludedBarColor properties.

This property also determines the SQL where clause generated in generateWhereClause() for filtering purposes. The value set here determines the number of values allowed on the slider.

Possible Values: equal | not-equal | less-than | greater-than | at-most | at-least | between | not-between

See the table below for a description and requirements of all possible values. value1 refers to the value of the first thumb position. value2 refers to the value of the final thumb position, if applicable.

Possible ValueNumber of ValuesWhere clause
equal1${field} = ${value1}
not-equal1${field} <> ${value1}
less-than1${field} < ${value1}
greater-than1${field} > ${value1}
at-most1${field} <= ${value1}
at-least1${field} >= ${value1}
between2${field} BETWEEN ${value1} AND ${value2}
not-between2${field} NOT BETWEEN ${value1} AND ${value2}
See also:
Example:
// renders the histogram so that all bins between
// the two handles are shaded with a blue color
slider.rangeType = "between";

// filters the layer view based on the configuration
// of the slider
layerView.filter = {
  where: slider.generateWhereClause("POPULATION")
}
standardDeviation Number

Indicates the standard deviation of the dataset. When set, computed dataLines will render on the histogram at the location of the given standard deviation above and below the average.

Example:
// stddev returned from summaryStatistics
slider.standardDeviation = stats.stddev;
standardDeviationCount Number

Indicates the number of standard deviation lines to render on the histogram from the [average].

Default Value:1
Example:
slider.standardDeviationCount = 2;
values Number[]

An array of either one or two numbers representing thumb positions on the slider. The number of values that should be indicated here depends on the associated rangeType.

See also:
Example:
const slider = new HistogramRangeSlider({
  min: 20,
  max: 100,  // data range of 80
  values: [50.4331],
  rangeType: "at-least"
  container: "sliderDiv"
});

The view model for the widget. This is a class that contains all the logic (properties and methods) that controls this widget's behavior. See the esri/widgets/HistogramRangeSlider/HistogramRangeSliderViewModel class to access all properties and methods on the Slider widget.

Method Overview

NameReturn TypeSummaryClass
String

A utility method used for building the value for a widget's class property.

more details
more detailsWidget

Destroys the widget instance.

more details
more detailsWidget
Boolean

Emits an event on the instance.

more details
more detailsWidget
String

Generates a SQL where clause based on a given field and the slider's rangeType.

more details
more detailsHistogramRangeSlider
Boolean

Indicates whether there is an event listener on the instance that matches the provided event name.

more details
more detailsWidget
Object

Registers an event handler on the instance.

more details
more detailsWidget

Widget teardown helper.

more details
more detailsWidget

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget
Object

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Renders widget to the DOM immediately.

more details
more detailsWidget

This method is primarily used by developers when implementing custom widgets.

more details
more detailsWidget

Method Details

classes(classNames){String}inherited

A utility method used for building the value for a widget's class property. This aids in simplifying CSS class setup.

Parameter:
classNames Array<(string|Array<string>|Object)>
repeatable

The class names.

Returns:
TypeDescription
StringThe computed class name.
See also:
Example:
// .tsx syntax showing how to set CSS classes while rendering the widget

render() {
  const dynamicIconClasses = {
    [CSS.myIcon]: this.showIcon,
    [CSS.greyIcon]: !this.showIcon
  };

  return (
    <div class={classes(CSS.root, CSS.mixin, dynamicIconClasses)} />
  );
}
destroy()inherited

Destroys the widget instance.

emit(type, event){Boolean}inherited

Emits an event on the instance. This method should only be used when creating subclasses of this class.

Parameters:
type String

The name of the event.

event Object
optional

The event payload.

Returns:
TypeDescription
Booleantrue if a listener was notified
generateWhereClause(field){String}

Generates a SQL where clause based on a given field and the slider's rangeType. This is a convenience function for data filtering or data queries.

Parameter:
field String

Name of the field used in the where clause. This field should correspond to the data used to generate the histogram associated with the slider.

Returns:
TypeDescription
StringThe SQL where clause to apply to a filter or query.
See also:
Example:
// renders the histogram so that all bins between
// the two handles are shaded with a blue color by default
slider.rangeType = "between";

// filters the layerview based on the configuration
// of the slider
layerView.filter = {
  where: slider.generateWhereClause("POPULATION")
}
hasEventListener(type){Boolean}inherited

Indicates whether there is an event listener on the instance that matches the provided event name.

Parameter:
type String

The name of the event.

Returns:
TypeDescription
BooleanReturns true if the class supports the input event.
on(type, listener){Object}inherited

Registers an event handler on the instance. Call this method to hook an event with a listener.

Parameters:

A event type, or an array of event types, to listen for.

listener Function

The function to call when the event is fired.

Returns:
TypeDescription
ObjectReturns an event handler with a remove() method that can be called to stop listening for the event(s).
PropertyTypeDescription
removeFunctionWhen called, removes the listener from the event.
Example:
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});
own(handles)inherited

Widget teardown helper. Any handles added to it will be automatically removed when the widget is destroyed.

Parameter:

Handles marked for removal once the widget is destroyed.

postInitialize()inherited

This method is primarily used by developers when implementing custom widgets. Executes after widget is ready for rendering.

render(){Object}inherited

This method is primarily used by developers when implementing custom widgets. It must be implemented by subclasses for rendering.

Returns:
TypeDescription
ObjectThe rendered virtual node.
renderNow()inherited

Renders widget to the DOM immediately.

scheduleRender()inherited

This method is primarily used by developers when implementing custom widgets. Schedules widget rendering. This method is useful for changes affecting the UI.

Event Overview

NameTypeSummaryClass
{oldValue: Number,type: String,value: Number}

Fires when a user changes the max value of the slider.

more details
more detailsHistogramRangeSlider
{oldValue: Number,type: String,value: Number}

Fires when a user changes the min value of the slider.

more details
more detailsHistogramRangeSlider
{index: Number,state: String,type: String,thumbIndices: Number[]}

Fires when a user drags a segment of the slider.

more details
more detailsHistogramRangeSlider
{index: Number,oldValue: Number,type: String,value: Number}

Fires when a user changes the value of a thumb via the keyboard arrow keys.

more details
more detailsHistogramRangeSlider
{index: Number,state: String,type: String,value: Number}

Fires when a user drags a thumb on the widget.

more details
more detailsHistogramRangeSlider
{index: Number,oldValue: Number,type: String,value: Number}

Fires when a thumb value changes on the widget.

more details
more detailsHistogramRangeSlider
{indices: Number[],oldValues: Number[],type: String,values: Number[]}

Fires when the values array changes on the Slider widget.

more details
more detailsHistogramRangeSlider

Event Details

max-change

Fires when a user changes the max value of the slider.

Properties:
oldValue Number

The former max value (or bound) of the slider.

type String

The type of the event. For this event, the type is always max-change.

value Number

The value of the max value (or bound) of the slider when the event is emitted.

min-change

Fires when a user changes the min value of the slider.

Properties:
oldValue Number

The former min value (or bound) of the slider.

type String

The type of the event. For this event, the type is always min-change.

value Number

The value of the min value (or bound) of the slider when the event is emitted.

segment-drag

Fires when a user drags a segment of the slider. A segment is the portion of the track that lies between two thumbs. Therefore, this is only applicable when two or more thumbs are set on the slider.

Properties:
index Number

The 1-based index of the segment in the slider.

state String

The state of the drag.

Possible Values: start | drag

type String

The type of the event. For this event, the type is always segment-drag.

thumbIndices Number[]

The indices of the thumbs on each end of the segment.

thumb-change

Fires when a user changes the value of a thumb via the keyboard arrow keys.

Properties:
index Number

The 0-based index of the updated thumb position.

oldValue Number

The former value of the thumb before the change was made.

type String

The type of the event. For this event, the type is always thumb-change.

value Number

The value of the thumb when the event is emitted.

thumb-drag

Fires when a user drags a thumb on the widget.

Properties:
index Number

The 0-based index of the updated thumb position.

state String

The state of the drag.

Possible Values: start | drag

type String

The type of the event. For this event, the type is always thumb-drag.

value Number

The value of the thumb when the event is emitted.

value-change
Deprecated since version 4.13.

Fires when a thumb value changes on the widget.

Properties:
index Number

The 0-based index of the thumb emitting the event.

oldValue Number

The former value of the thumb before the change was made.

type String

The type of the event. For this event, the type is always value-change.

value Number

The value of the thumb when the event is emitted.

values-change
Deprecated since version 4.13.

Fires when the values array changes on the Slider widget.

Properties:
indices Number[]
optional

The 0-based indices of the thumbs emitting the event.

oldValues Number[]

The former values of the thumbs before the changes were made.

type String

The type of the event. For this event, the type is always values-change.

values Number[]

The values of the thumbs when the event is emitted.

API Reference search results

NameTypeModule
Loading...