Select to view content in your preferred language

How to base label color on field value?

174
3
3 weeks ago
Labels (1)
CathrynAsp
New Contributor

Hi all,

I am very new to ArcGIS Pro and have a question about changing label colors based on a condition. 

I am creating a map of the US where I want to display a label on each state, however, the shades of each state prevent the label from being seen if I do it all one color. 

The symbology is based on a field that is a % and the symbol I want to display is that same %, by state. If the symbol is light I want the label to be black, and if the symbol is dark I want the label to be white. For some reason I cannot figure this out. 

Here is the code I have based on searching online: 

 

var r1 = $feature['T_Mapping_Renters$_.Percentage_Point_Difference_Fro'];
var output = When(r1 (>= -.005) && (<= .005), `<p style=color:rgb(255,255,255)></p>`,
                  r1 > .005, `<p style=color:rgb(0,0,0)></p>`,
                  r1 < -.005, `<p style=color:rgb(0,0,0)></p>`)

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

 

 

Not at all sure what lines 6-9 are doing here, and also need to transform the label into a percent:

 

Round($feature['T_Mapping_Renters$_.Percentage_Point_Difference_Fro']*100,0) + "%"

 

This is an inspiration photo as an example, would also love to know how to "pop out" the New England states that do not fit on the map"

CathrynAsp_0-1717685695273.png

 

 

I hope that makes sense! I would greatly appreciate the help. 

Tags (2)
0 Kudos
3 Replies
AubriKinghorn
Esri Regular Contributor

Hi! That's cool map inspiration. I don't have a programmatic answer, but you can do this in the application itself by using label classes. There's an option to create label classes from symbology, this will create a set of labels for each symbol color and then you can address the label color for that class. Learn how to create label classes and more details here: https://pro.arcgis.com/en/pro-app/latest/help/mapping/text/label-classes.htm#ESRI_SECTION1_837E8DE40...

Cheers,
Aubri
CathrynAsp
New Contributor

This helped a ton! Thank you so much for linking this. I was wondering if you happen to know a way to "pop out" the smaller states that cannot effectively contain labels?

0 Kudos
AubriKinghorn
Esri Regular Contributor

I do actually! Labeling has lots of options, it can be hard to find the right ones. But you can place labels outside of polygons: https://pro.arcgis.com/en/pro-app/latest/help/mapping/text/place-labels-outside-polygons-when-they-w.... You can also change the label placement strategies. Key numbering might be useful if you don't like the place outside of plygon results. https://pro.arcgis.com/en/pro-app/latest/help/mapping/text/why-use-additional-strategies-for-placing...

Cheers,
Aubri