Value Mapping to Change Text Color

Good morning Team,

I have a tag that with the query listed. I have mapped it to change it to a percentage but I would like the color of text to change when it is over certain percent/value.

I have tried adding an additional transform using a number range and a style class but this did not work. I also tried using a number range and color to change text color.

Any help would be great.

SELECT
    COUNT(state) / 19
FROM
    Clemens.accumulation_lanes2
WHERE
    Clemens.accumulation_lanes2.state NOT LIKE 'open'
AND  Clemens.accumulation_lanes2.lane NOT LIKE '9' ;

You can use an Expression or Script Transforms to use if Statements to set your ranges and what values would be returned.

Expression - My understanding is this uses less memory, but obviously messier to read / edit.

IF ({value} < 0.25, "Statement for Less than 25%", 
   IF ({value} < 0.50, "Statement for 25%-50%", "Statement for 50% and Above"))

Script - more traditional if statements.

if value < 0.25:
   return "Statement for Less than 25%"
elif value < 0.50:
   return "Statement for 25%-50%"
else:
   return "Statement for 50% and Above"

With those in mind, depending on where the binding is, you could have the returns be the color / class.

I think a Map Transform will do what you want quite efficiently.

  1. Create a binding on the property that needs it.
  2. Select the Tag or Query binding.
  3. If a tag, then select the tag.
  4. Create a Map Transform.
  5. I don't know why I felt the need to put a number here.
  6. Green band. Note that [ and ] are inclusive but ( and ) are exclusive.
  7. Yellow band.
  8. The everything else band.
  9. The result.

There's a video tutorial link in there.

3 Likes

Thank you for such a quick response.

I believe what you are saying is to use one of these and then map the statment to a style or color??

I would like to keep the % listed rather than a statement. So rather than transform into a statment I could use the % or value to determine when the color chagnes on the text of the LED display.

image

Thanks Transistor,

I have the initial mapping working but I cannot map a second time to format the text color.

remove the "" in the input type value and dont do the format on here

Incorrect map transform

You're trying to apply a color to the label's value property. You can't do that.

You need to create a separate binding to textStyle.color as shown in step 1 of my previous post.


General comment: don't use the seven-segment display. It was great in the 1970s but on HMIs contrast is poor, character definition is poor and it really impedes legibility. Use labels with all the benefits of scalable vector fonts. Make beautiful HMIs! Think like a graphic designer who understands how the page will be scanned and how information will be read and interpreted. The modern, High-Performance HMIs are recommending muted colors for everything that's normal and using yellows and reds for deviations and alarms.

Map numeric range

My mistake. The " were because I forgot to set Input Type = Numeric Range.

@Transistor, That definitely is a better solution :smile:; I apparently need to go back through the mapping transform documentation (thanks for the link haha); I didn't realize you could set ranges.

Ahh i see what you are saying. I will update and map the color. Let me tray that.

And you say labels are best to use? I will use that. I am working out how best to "streamline" my dashboards and any tips will be welcome. In fact any good pics of a nice dashboard would be great. I have reviewed the ones on the general discussion but nothing really fits what i need.

Have a look for articles on High-Performance HMIs. Have a look at

(I just glanced at it but it seems to be on the right track.)