Select to view content in your preferred language

Format multiple attributes in popup text based on same color bins

142
1
2 weeks ago
GregMayes
New Contributor

I'd like to build a table in a popup that shows a matrix of different attribute values while formatting the cell background colors using the same range, e.g.

≤70% = red
70% to ≤80% = orange
80% to ≤90% = yellow
90% to ≤95% = green
>95% = blue

I have 30 different attribute values in the matrix table and I have to believe there's a better way to do this in arcade than writing an if else statement for each?

 

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

You can write a function that returns the color for the attribute passed in as a parameter.

function bgColor(attribute) {
  when (attribute <= 70, "red",
        attribute <= 80, "orange",
        attribute <= 90, "yellow",
        attribute <= 95, "green",
        "blue")
}

//in use
var theColor = bgColor($feature.attribute)