I am working with monitoring well sample data and have test results labelled for April and June. But I also want to set a condition to output a red label if the value is 10 or higher. And I don't want the 'NS' labels colored, just the 10 or higher values. Here is what I am looking at.
Do you mind if the date is colored also? Probably the easiest things to do would be to set up two label classes, one for each of the value ranges based on the test result:
My example above has two different label classes based on the size of the feature. Then in the label class, use the SQL tab to set the criteria based on the results value, and style accordingly
Dynamic labels in Pro are pretty limited, but conditionally changing colors is possible.
Since there are "NS" values, are those actually text fields? I'll assume so for this post.
In text, what we're doing is
Since we're doing a series of steps more than once, I'm going to use a custom function.
Here's what the code could look like:
function colorCode(x) {
// default color is black
var col = 'red = "0"'
// check for numeric value
if (x != 'NS') {
// convert to number
x = Number(x)
// greater than 10, color is red
if (x >= 10) {
col = 'red = "255"'
}
}
// return text
return `<CLR ${col}>${x}</CLR>`
}
return `April: ${colorCode($feature['ArsTestApr'])}
June: ${colorCode($feature['ArsTestJun'])}`
Note, I haven't tested this in Pro. In other contexts, a literal line break in a `backtick string` will come through in the output, but I know Pro can be a little different in how it handles Arcade.
Here's me testing this with some made up values: