Select to view content in your preferred language

ColorVariable not working

344
1
Jump to solution
12-12-2022 11:34 AM
MichaelWen_Timmons
Occasional Contributor

I have a JS API 4x web application that uses a Feature Layer that is populated client-side by data coming from a web socket. I am trying to use the ColorExpression to vary the color on the symbol.

      const colorExpression = `
      var color = $feature.color;
      var code = Decode(color, '#990000', 0, '#006600', 1, '#000000', 2);
      return code;
      `;
      breadcrumbRenderer.visualVariables = [{
        type: "rotation",
        field: "heading",
        rotationType: "geographic"
      },{
        type: "color",
        valueExpression: colorExpression,
        stops: [
          { value: 0, color: "#990000"},          
          { value: 1, color: "#006600"},
          { value: 2, color: "#000000"}
        ]
      }]
 
The rotation variable works fine but the color variable is ignored, with everything showing up in the default color. If I use something like "0" for valueExpression then it would render in the 0 color, but for some reason my Arcade Expression is not recognized. Can someone help?
 

 

0 Kudos
1 Solution

Accepted Solutions
KristianEkenes
Esri Regular Contributor

Your Arcade expression appears to be missing a default value in the Decode function. Add another param, like the number 3, or null so the expression can properly evaluate.

 

var code = Decode(color, '#990000', 0, '#006600', 1, '#000000', 2, null);

View solution in original post

0 Kudos
1 Reply
KristianEkenes
Esri Regular Contributor

Your Arcade expression appears to be missing a default value in the Decode function. Add another param, like the number 3, or null so the expression can properly evaluate.

 

var code = Decode(color, '#990000', 0, '#006600', 1, '#000000', 2, null);
0 Kudos