Skip to content

This sample demonstrates how to generate a data-driven class breaks visualization based on a classification method used to classify data from a numeric field in a FeatureLayer.

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

const params = {
layer: layer,
valueExpression: getValueExpression(fieldSelect.value),
view: viewElement.view,
classificationMethod: classificationMethod,
numClasses: parseInt(numClassesInput.value),
legendOptions: {
title: "% population with " + fieldLabel,
},
};
// generate the renderer and set it on the layer
const rendererResponse = await colorRendererCreator.createClassBreaksRenderer(params);
layer.renderer = rendererResponse.renderer;

You can also create a ClassedColorSlider to allow the user to create manual class breaks.

// if manual classification method is selected, then create
// a classed color slider to allow user to manually modify
// the class breaks starting with the generated renderer
const updateColorSlider = async (rendererResult) => {
const histogramResult = await histogram({
layer: layer,
valueExpression: getValueExpression(fieldSelect.value),
view: viewElement.view,
numBins: 100,
});
classedColorSlider.updateFromRendererResult(rendererResult, histogramResult);
};

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 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.

Additional visualization samples and resources