Change font color based on if statement

1472
2
07-22-2020 12:23 PM
SallyGalewski
New Contributor II

NEWBIE TO ARCADE!!!

I am in AGOL trying to configure an expression for a calculated field (Hcalc).  Currently the expression is: 

return ($feature.ItemA / $feature.ItemB) * 200

which simply calculates based on the tech's input.  I'd like to have the font color change to red, if the result is over 10, which will prompt the tech to re-run the test.  If the result is under 10, the font color remains black.

so the IIf statement in arcade shows this:

IIf(conditionalExpression, valueIfTrue, valueIfFalse)

my expression should be something like this?

var Hcalc = (($feature.ItemA / $feature.ItemB) * 200)
IIf (Hcalc > 10, <font.color> = "red", <font.color> = "black")

Any help is appreciated.

Thanks in advance!

0 Kudos
2 Replies
XanderBakker
Esri Esteemed Contributor

Hi Sally Galewski ,

In ArcGIS Online, you cannot return font formatting or colors in a single Arcade expression. You can use the expression that you already had and use custom HTML formatting in the pop-up using another arcade expression. The first continues to return the value you calculate, the second returns the color code to be applied to the text depending on the value calculate. 

The HTML for your pop-up could look like this:

<p style="color:{expression/expr1};">{expression/expr0}</p>

..  in this example the expression 1 will contain the color code:

var Hcalc = (($feature.ItemA / $feature.ItemB) * 200)

if (Hcalc > 10) {
    return "rgb(255, 0, 0)";
} else {
    return "rgb(0, 0 , 0)";
}
XanderBakker
Esri Esteemed Contributor

Hi sallygal2004 

To provide a visual example of applying the solution above,this is what you can get:

0 Kudos