Hello!
I have a quick question about creating colored labels in AGOL with arcade. I am trying to filter out my data with If/else statements for the appropriate range for a given color, then assigning a color to that value in the label with Text formatting tags. The arcade code is below. Any other ideas on how to create this would help as well!
I am new to arcade, so thanks for bearing with me!
## convert number to string
var temp = Text($feature["tmdb_f"])
## partition each range of temperature out first, then assign colored label to that range.
if ($feature["tmdb_f"] >=90) {
return "<CLR red='139'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=80) {
return "<CLR red='255'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=70) {
return "<CLR red='255', green= '153', blue='51'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=60) {
return "<CLR red='255', green= '215'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=50) {
return "<CLR red='50', green= '205', blue='50'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=40) {
return "<CLR green= '128'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=30) {
return "<CLR green= '255', blue='255'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=20) {
return "<CLR green= '128', blue='128'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=10) {
return "<CLR blue='139'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
if ($feature["tmdb_f"] <=0) {
return "<CLR red='148', blue='211'><FNT size = '14'>" + [temp] + "</FNT></CLR>"
}
else {
return null
}
There are a couple of errors in your expression. Please see example below:
// convert number to string
var tmdb_f = $feature["tmdb_f"];
// partition each range of temperature out first
// then assign colored label to that range.
if (tmdb_f >=90) {
return "<CLR red='139'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=80) {
return "<CLR red='255'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=70) {
return "<CLR red='255', green= '153', blue='51'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=60) {
return "<CLR red='255', green= '215'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=50) {
return "<CLR red='50', green= '205', blue='50'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=40) {
return "<CLR green= '128'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=30) {
return "<CLR green= '255', blue='255'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=20) {
return "<CLR green= '128', blue='128'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=10) {
return "<CLR blue='139'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else if (tmdb_f >=0) {
return "<CLR red='148', blue='211'><FNT size = '14'>" + tmdb_f + "</FNT></CLR>";
} else {
return tmdb_f;
}
Please take into account:
Thank you very much for the corrections! I input this into the AGOL label expressions, however it didn't load correctly. Then found a post with a similar question and learned that Arcade within AGOL doesn't recognize the text formatting tags. Will this be added to AGOL within the future by chance?
Good catch, that is right the formatting is not supported in AGOL. Since the idea is that all ArcGIS products integrate correctly, I would assume that at some point this will be implemented in ArcGIS Online.
Hi Xander,
Am I understanding correctly that you can't use formatting tags in AGOL?
I am having two issues:
I can't get the iif statement to work
and
Am I able to change the color of just the acreage number? - Round(aggAcreage,2)
(I know how to change the color of the entire expression)
var intersectingAggDiss = Intersects(FeatureSetByName($map,"COS Aggregated Vacant Parcels - No Structure"), $feature);
var aggAcreage = 0;
for (var aggacre in intersectingAggDiss) {
aggAcreage += aggacre.Acreage;
}
iif (aggAcreage = 0, '', 'The aggregate acreage is: ' + Round(aggAcreage,2));
//return 'The aggregate acreage is: ' + Round(aggAcreage,2);
Hi Gerald Sneary ,
Am I understanding correctly that you can't use formatting tags in AGOL?
Unfortunately, that is correct. Hopefully this will come in the feature. (I haven't checked with the beta map viewer)
For a label you cannot use Arcade to create the formatting. You could use multiple layers, but it is better not to go there. You can, in the pop-up, use conditional formatting, but it requires multiple expressions and when using access to other layers, this will probably have an impact on performance.
Your condition on line 6 is probably missing the required double "==":
iif (aggAcreage == 0, '', 'The aggregate acreage is: ' + Round(aggAcreage,2));
I got my if-else statement to work. Now am I able to use <CLR> or something else to change the color of - Round(aggAcreage,2) ?
var intersectingAggDiss = Intersects(FeatureSetByName($map,"COS Aggregated Vacant Parcels - No Structure"), $feature);
var aggAcreage = 0;
for (var aggacre in intersectingAggDiss) {
aggAcreage += aggacre.Acreage;
}
if (aggAcreage == 0){
aggAcreage = '';
} else {
'The aggregate acreage is: ' + Round(aggAcreage,2);
}
Hi gerald.sneary80 ,
I recently wrote a document about conditionally hiding or showing rows in a table with Arcade: Conditional Field display with Arcade in Pop Ups (revisited)
The same technique could be applied to define the color of a text. You will need to use a custom html pop-up.