Select to view content in your preferred language

Varying Color in ArcGIS Online Dashboard Based on Field Value

563
2
Jump to solution
09-27-2024 06:51 AM
j_chad_wich
New Contributor

I'm attempting to vary the color of a specific word depending on what is added (critical, high, medium, or low), but the only color showing up is the yellow (#ecf229) from the else statement. Does anyone know what I'm getting wrong with the if/else statement? I believe that's where the issue might be but I'm not certain.

Here's the expression I've added to the advanced formatting for the list.

var lOI = ''
if ($datapoint.level_of_impact=="Critical"){lOI= '#e01d1d'}
else if($datapoint.level_of_impact=="High"){lOI= '#ff7300'}
else if($datapoint.level_of_impact=="Medium"){lOI= '#73b2ff'}
else {lOI= '#ecf229'}

return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
attribute1: lOI
// attribute2: ''
}
}

Here's what I have in the source for the line item template, which seems to be working correctly as it is adding a color - just not always the correct one.

<p><strong><span style="color:{expression/attribute1}">{level_of_impact}</span></strong></p>

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Is that field in a domain? If so, you'll need to use the domain code or the DomainName function

var level = DomainName($datapoint, "level_of_impact");
var lOI = When( 
  level == "Critical",  "#e01d1d",
  level == "High", "#ff7300",
  level == "Medium", "#73b2ff",
  "#ecf229"
);

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

Is that field in a domain? If so, you'll need to use the domain code or the DomainName function

var level = DomainName($datapoint, "level_of_impact");
var lOI = When( 
  level == "Critical",  "#e01d1d",
  level == "High", "#ff7300",
  level == "Medium", "#73b2ff",
  "#ecf229"
);
j_chad_wich
New Contributor

Perfect! That's the mistake I was making. Thank you!

0 Kudos