Select to view content in your preferred language

Change text color based on value/label using Arcade

3138
6
Jump to solution
10-31-2023 11:53 AM
Labels (1)
dwold
by
Frequent Contributor

In my pop-up, I'd like to have the text correspond with the map symbology color. Any suggestions on how to do so? I tried the following below with no success:

dwold_0-1698778268319.pngdwold_1-1698778304052.png

dwold_2-1698778317863.png

 

 

0 Kudos
3 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

There are a couple of ways to do that. The original way is outlined in this blog.

The more modern way is to use the Arcade element, which allows you to use HTML tags directly. I've simpified your code, using the When function (replacing all the ifs) and template literals.

var r1 = $feature.["Risk_Level"];
var output = When(r1 == 0, "Lowest",
                  r1 < 2, `<p style=color:rgb(142,211,231)>Very low</p>`,
                  r1 < 3, `<p style=color:rgb(89,184,98)>Low</p>`,
                  r1 < 4, `<p style=color:rgb(255,255,63)>Moderate</p>`,
                  r1 < 5, `<p style=color:rgb(254,166,32)>High</p>`,
                  r1 < 6, `<p style=color:rgb(252,56,57)>Very high</p>`,
                  `<p style=color:rgb(205,0,103)>Highest</p>`)

return { 
	type : 'text', 
	text : output //this property supports html tags 
}

Note: when posting code, using an image makes it more difficult for us to copy and paste to give an answer. Instead, use the Insert/Edit code sample icon

View solution in original post

dwold
by
Frequent Contributor

@KenBuja do you see anything I am missing in the code?

this my pop-up:

dwold_0-1698848805231.png

 

 

var r1 = $feature["Risk_Level"];
var output = When(r1 == 0, "Lowest",
                  r1 < 2, `<p style=color:rgb(142,211,231)>Very low</p>`,
                  r1 < 3, `<p style=color:rgb(89,184,98)>Low</p>`,
                  r1 < 4, `<p style=color:rgb(255,255,63)>Moderate</p>`,
                  r1 < 5, `<p style=color:rgb(254,166,32)>High</p>`,
                  r1 < 6, `<p style=color:rgb(252,56,57)>Very high</p>`,
                  `<p style=color:rgb(205,0,103)>Highest</p>`)

return { 
	type : 'text', 
	text : output //this property supports html tags 
}

 

 

I also tried this with no luck:

 

var r1 = $feature["Risk_Level"];
var output = When(r1 == 0, "Lowest",
                  r1 < 1, `<p style=color:rgb(142,211,231)>Very low</p>`,
                  r1 < 2, `<p style=color:rgb(89,184,98)>Low</p>`,
                  r1 < 3, `<p style=color:rgb(255,255,63)>Moderate</p>`,
                  r1 < 4, `<p style=color:rgb(254,166,32)>High</p>`,
                  r1 < 5, `<p style=color:rgb(252,56,57)>Very high</p>`,
                  r1 < 6, `<p style=color:rgb(205,0,103)>Highest</p>`)

return { 
	type : 'text', 
	text : output //this property supports html tags 
}

 

dwold_1-1698849372165.png

 

View solution in original post

0 Kudos
KenBuja
MVP Esteemed Contributor

You have to add this code to a Arcade element

popup.png

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

There are a couple of ways to do that. The original way is outlined in this blog.

The more modern way is to use the Arcade element, which allows you to use HTML tags directly. I've simpified your code, using the When function (replacing all the ifs) and template literals.

var r1 = $feature.["Risk_Level"];
var output = When(r1 == 0, "Lowest",
                  r1 < 2, `<p style=color:rgb(142,211,231)>Very low</p>`,
                  r1 < 3, `<p style=color:rgb(89,184,98)>Low</p>`,
                  r1 < 4, `<p style=color:rgb(255,255,63)>Moderate</p>`,
                  r1 < 5, `<p style=color:rgb(254,166,32)>High</p>`,
                  r1 < 6, `<p style=color:rgb(252,56,57)>Very high</p>`,
                  `<p style=color:rgb(205,0,103)>Highest</p>`)

return { 
	type : 'text', 
	text : output //this property supports html tags 
}

Note: when posting code, using an image makes it more difficult for us to copy and paste to give an answer. Instead, use the Insert/Edit code sample icon

dwold
by
Frequent Contributor

@KenBuja Thank you!!!

0 Kudos
dwold
by
Frequent Contributor

@KenBuja do you see anything I am missing in the code?

this my pop-up:

dwold_0-1698848805231.png

 

 

var r1 = $feature["Risk_Level"];
var output = When(r1 == 0, "Lowest",
                  r1 < 2, `<p style=color:rgb(142,211,231)>Very low</p>`,
                  r1 < 3, `<p style=color:rgb(89,184,98)>Low</p>`,
                  r1 < 4, `<p style=color:rgb(255,255,63)>Moderate</p>`,
                  r1 < 5, `<p style=color:rgb(254,166,32)>High</p>`,
                  r1 < 6, `<p style=color:rgb(252,56,57)>Very high</p>`,
                  `<p style=color:rgb(205,0,103)>Highest</p>`)

return { 
	type : 'text', 
	text : output //this property supports html tags 
}

 

 

I also tried this with no luck:

 

var r1 = $feature["Risk_Level"];
var output = When(r1 == 0, "Lowest",
                  r1 < 1, `<p style=color:rgb(142,211,231)>Very low</p>`,
                  r1 < 2, `<p style=color:rgb(89,184,98)>Low</p>`,
                  r1 < 3, `<p style=color:rgb(255,255,63)>Moderate</p>`,
                  r1 < 4, `<p style=color:rgb(254,166,32)>High</p>`,
                  r1 < 5, `<p style=color:rgb(252,56,57)>Very high</p>`,
                  r1 < 6, `<p style=color:rgb(205,0,103)>Highest</p>`)

return { 
	type : 'text', 
	text : output //this property supports html tags 
}

 

dwold_1-1698849372165.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You have to add this code to a Arcade element

popup.png

JasminePrater
Frequent Contributor

I'm trying to do something similar, except I want the HydrantID field to be the label where it turns red if Public and yellow if Private.  The Public or Private information is in the Owner field.  Is that something that can be done with modifications to this code?

ctalleygreenville
Regular Contributor

Thank you Ken, this is very helpful.

0 Kudos