Skip to content

This sample demonstrates how to visualize features in a layer along a continuous color ramp based on data in a numeric field.

In this case, we'll use a SimpleRenderer with visual variables to alter the color of each feature based on the percentage of the population living below the poverty line.

Prior to completing the following steps, you should be familiar with the Map component and FeatureLayer. The basic components of this app, such as creating instances of the Map component, and understanding HTML and CSS structure will not be reviewed in this sample.

Create a SimpleRenderer with a default symbol

All that's required when creating a renderer with a continuous color ramp is a SimpleRenderer with visual variables.

In the snippet below, we set a default symbol on the symbol property of the renderer. We don't need to define a color on the symbol because each feature's color will be determined by visual variables.

Define default symbol in the renderer
Use dark colors for code blocksCopy
38 39 40 41 42 43 44 45 46 47 48 49 50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
      let renderer = {
        type: "simple", // autocasts as new SimpleRenderer()
        label: "U.S. County", // legend label for the default symbol
        symbol: {
          type: "simple-fill", // autocasts as new SimpleFillSymbol()
          outline: {
            // autocasts as new SimpleLineSymbol()
            // makes the outlines of all features consistently light gray
            color: [128, 128, 128, 0.2],
            width: "0.5px",
          },
        },
      };

Set a color visual variable on the renderer

Setting a color visual variable requires a field name, which indicates the data to for the visualization. You can also specify a normalizationField to normalize data values specified in field. In this sample, we're pointing the field to POP_POVERTY, which stores the total number of people living in poverty within the boundaries of the feature. We'll normalize based on the total population with the TOTPOP_CY field.

Then you set the color ramp using a series of stops in the stops array.

Define color visual variable on the renderer
Use dark colors for code blocksCopy
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
      renderer.visualVariables = [
        {
          type: "color", // indicates this is a color visual variable
          field: "POP_POVERTY", // total population in poverty
          normalizationField: "TOTPOP_CY", // total population
          legendOptions: {
            title: "% population in poverty by county", // legend label for the visual variable
          },
          stops: [
            {
              value: 0.1, // features where < 10% of the pop in poverty
              color: "#FFFCD4", // will be assigned this color (beige)
              label: "<10%", // label to display in the legend
            },
            {
              value: 0.3, // features where > 30% of the pop in poverty
              color: "#350242", // will be assigned this color (purple)
              label: ">30%", // label to display in the legend
            },
            // features with values between 0.1 and 0.3 will be assigned
            // a color on a ramp between beige and purple proportional
            // to where the value falls between 0.1 and 0.3
          ],
        },
      ];

Once the renderer is defined, you can set it on the layer and the view and legend will automatically update.

Additional visualization samples and resources

Esri Color Ramps

Browse hundreds of color ramps to use in your data visualizations

Techniques and best practices

Various techniques and best practices to follow when styling layers.

Image preview of related sample Data-driven continuous size

Data-driven continuous size

Image preview of related sample Data-driven extrusion

Data-driven extrusion

Image preview of related sample Data-driven opacity

Data-driven opacity

Image preview of related sample Thematic multivariate visualization (2D)

Thematic multivariate visualization (2D)

Image preview of related sample Thematic multivariate visualization (3D)

Thematic multivariate visualization (3D)

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