Generate continuous color visualization

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

This sample demonstrates how to generate a data-driven continuous color visualization based on statistics returned from a numeric field in a FeatureLayer.

This is accomplished with the createContinuousRenderer() in the color renderer creator helper object. All that is required for generating a renderer is a Feature Layer and a field name.


var params = {
  layer: povLyr,
  basemap: map.basemap,
  field: "POP_POVERTY",
  normalizationField: "TOTPOP_CY",
  theme: "above-and-below"
};

colorRendererCreator.createContinuousRenderer(params)
  .then(function(response){

    // set the renderer to the layer
    povLyr.renderer = response.renderer;
  });

To generate the histogram used by the slider, simply pass similar parameters to the histogram() function. You can then pass the resulting object to the ColorSlider.

histogram({
  layer: povLyr,
  field: "POP_POVERTY",
  normalizationField: "TOTPOP_CY"
})
  .then(function(histogram){
    // add the histogram to the color slider
    var colorSlider = new ColorSlider({
      statistics: stats,  // stats returned from createContinuousRenderer()
      visualVariable: colorVV,  // color visual variable returned from createContinuousRenderer()
      histogram: histogram,  // returned from histogram()
      numHandles: 3,
      syncedHandles: true,
      container: "slider"
    });

    view.ui.add(colorSlider, "bottom-right");
  });

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.

A word of caution

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 Visualization overview: Smart mapping API 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.

Additional visualization samples and resources

Sample search results

TitleSample

There were no match results from your search criteria.