This sample demonstrates how to generate a data-driven continuous color visualization based on statistics returned from a numeric field in a FeatureLayer.
To generate the histogram used by the slider, simply pass similar parameters to the histogram() function. You can then pass the resulting object to theColorSlider.
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
histogram({
layer: layer,
valueExpression: colorParams.valueExpression,
view: view,
numBins: 70}).then((histogramResult) => {
// Construct a color slider from the result of both// smart mapping renderer and histogram methodsconst colorSlider = ColorSlider.fromRendererResult(rendererResult, histogramResult);
colorSlider.container = "slider";
colorSlider.primaryHandleEnabled = true;
view.ui.add("containerDiv", "bottom-left");
});
After the slider is set up with the statistics of the FeatureLayer, you can listen to its events to update the renderer of the layer with the output visual variable in the event object.
Keep in mind that generating renderers should be avoided in most applications because of the performance cost affecting the end user. As stated in the Smart Mapping guide topic, the Smart Mapping APIs were designed for two types of applications: data exploration apps and visualization authoring apps similar to ArcGIS Online. In all other cases, renderers should be saved to the layer or manually created using any of the renderer classes.