Select to view content in your preferred language

Arcade expression to control text color

5301
8
Jump to solution
12-20-2022 02:42 PM
JohnMedema
New Contributor III

Hi,

I am trying to control the background color of a list element using an arcade expression.  The $datapoint.division contains several string values e.g. Central Arizona.  Ideally I would like this expression to execute based on the various division values and color code the background of each list element based on the string value of $datapoint.division.

Here is my expression.  @DougBrowning , figured you can solve this in the blink of an eye.

var color = IIF($datapoint.division == "Central Arizona", '#F3DED7', '')
return {
textColor: '',
backgroundColor: color,
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
// attributes: {
// attribute1: '',
// attribute2: ''
// }
}

1 Solution

Accepted Solutions
JenniferAcunto
Esri Regular Contributor

Have you double checked your Division values? You want to use the name value and not the label. Are you using the Globals tab to add your field to your expression? If not, do that so that you know the syntax is correct. Also, try returning it as an attribute and then simply calling that in your list. That way you can see what, if anything your statement is returning. 

JenniferAcunto_1-1671635770839.png

 

JenniferAcunto_2-1671635803292.png

 

- Jen

View solution in original post

8 Replies
KinleyWinchester
New Contributor III
0 Kudos
JenniferAcunto
Esri Regular Contributor
var color = When( 
        $datapoint.division == 'Central Arizona', '#F3DED7', 
        $datapoint.division == 'Northern Arizona', '#981e1d', 
        $datapoint.division == 'Southern Arizona', '#f7b538', '') 

 

Dashboards That Pop: Arcade

- Jen
JohnMedema
New Contributor III

Hi Jennifer, thank you for the input.

I have applied the arcade expression and set  textColor: color to call my variable color. No results.  Is there a step I am missing?

var color = When(
$datapoint.division == 'Central Arizona', '#AC734A',
$datapoint.division == 'Piaute Pipeline', '#84AC4A',
$datapoint.division == 'Southern Nevada', '#4A99AC', '')

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

JohnMedema_0-1671635049547.png

 

 

0 Kudos
JenniferAcunto
Esri Regular Contributor

Have you double checked your Division values? You want to use the name value and not the label. Are you using the Globals tab to add your field to your expression? If not, do that so that you know the syntax is correct. Also, try returning it as an attribute and then simply calling that in your list. That way you can see what, if anything your statement is returning. 

JenniferAcunto_1-1671635770839.png

 

JenniferAcunto_2-1671635803292.png

 

- Jen
JohnMedema
New Contributor III

Thank you Jennifer!  

Ed_
by MVP Regular Contributor
MVP Regular Contributor

Hi @JenniferAcunto ,

Hope all is well, so I too have a color related question, figured I should ask it here. Based on the code (template literals,) below how can I change the color individually of each text string and field value?

Code:

 

 

for (var f in intersectLayer){ 
   popup += `<b>Area:</b> ${f.AREAFT} <br><br>

  
  <b>Length:</b> ${f.LENFT} <br><br>
  
  
  <b>ID:</b> ${f.ID} <br><br>
`
}  

 

 
Desired Output:

Area: Value

Length: Value

ID: Value

Question | Analyze | Visualize
0 Kudos
JenniferAcunto
Esri Regular Contributor

I'm not really an Arcade person. I just know a few tricks I use for Dashboards. I recommend you post this as a question so that the general community can see it.

- Jen
Ed_
by MVP Regular Contributor
MVP Regular Contributor

No worries and thank you for the quick response 🙂

Question | Analyze | Visualize
0 Kudos