I'm trying to essentially write an If...Then...Else statement using Arcade to change the text color in a Dashboard Indicator. I know what I need to do I just don't know the proper syntax for writing it and I'm having a problem finding a similar example.
var color = '' // using the var to change the color attribute
Decode($datapoint["capdep25"], //attempting to using the "capdep25" column
<=.25, {color = 'DF73FF'}, //if value is less than .25 make it pink
>.25 AND <=.50 , {color = '0070FF'}, //if value is between than make it blue
>.50 AND <=.75, {color = '38A800'}, //if value is between than make it green
>.75, {color = 'E60000'}, 0 //if value is greater than make it red
);
I'm not sure if decode is the correct way to do this or there is a better way.
Thanks for the help in advance!
Solved! Go to Solution.
Decode() is a switch/case statement, it matches the values exactly. You want When() , which is a nested if/else.
Also, take a look at the logical operators.
var cd25 = $datapoint["capdep25"
var color = When(
cd25 <= 0.25, "DE73FF",
cd25 > 0.25 && cd25 <= 0.5, "0070FF",
cd25 > 0.5 && cd25 <= 0.75, "38A800",
"E60000"
)
You need to include the "#" in your color codes. And you can make your code a little simpler
var cd25 = $datapoint["capdep25"];
var color = When(
cd25 > .001 && cd25 <= 0.25, "#DE73FF", //pink
cd25 <= 0.5, "#0070FF", //blue
cd25 <= 0.75, "#38A800", //green
"#E60000" //red
);
Decode() is a switch/case statement, it matches the values exactly. You want When() , which is a nested if/else.
Also, take a look at the logical operators.
var cd25 = $datapoint["capdep25"
var color = When(
cd25 <= 0.25, "DE73FF",
cd25 > 0.25 && cd25 <= 0.5, "0070FF",
cd25 > 0.5 && cd25 <= 0.75, "38A800",
"E60000"
)
Thank you for the help and yeah, I definitely need to look at those operators I was trying to hack something together after work and was kind of out of patience at that point. I appreciate your help!
Ok, this time I'm at a loss. My indicator text is coming up black now for all values. I'm assuming it has to by that my statement logic is somehow incorrect, but it seems fine to me.
var cd25 = $datapoint["capdep25"];
var color = When(
cd25 > .001 && cd25 <= 0.25, "DE73FF", //pink
cd25 > .25 && cd25 <= 0.5, "0070FF", //blue
cd25 > 0.5 && cd25 <= 0.75, "38A800", //green
"E60000" //red
);
You need to include the "#" in your color codes. And you can make your code a little simpler
var cd25 = $datapoint["capdep25"];
var color = When(
cd25 > .001 && cd25 <= 0.25, "#DE73FF", //pink
cd25 <= 0.5, "#0070FF", //blue
cd25 <= 0.75, "#38A800", //green
"#E60000" //red
);
Thank you @KenBuja . That's why my profile pic is the rolling eye emoji. It's usually something silly I'm missing.