Background Color Change

I have numeric indicators and need to have their background colors changed based on the value of two tags. The first tag is the process setpoint and the second tag is the actual process value (this is the value in the in numeric indicator). When the process value is within 0-2% of the setpoint Background Color A, Above or below 3-5% of the setpoint Background Color B, Above or below more than 5% of the setpoint Background Color C.

Best way to proceed?

My method (NooB) would be to add 6 custom properties to the indicator.
SP,PV,plus2,neg2,plus5,neg5.
Bind SP and PV to the appropriate tags.
The negx and plusx would be expressions:

{Root Container.Numeric Label.sp}+({Root Container.Numeric Label.sp}/100*2)

etc.

The Background Color would then have an expression:

if({pv}>{Root Container.Numeric Label.neg2}&&{pv}<{Root Container.Numeric Label.plus2},"71,255,71", if({pv}>{Root Container.Numeric Label.neg5}&&{pv}<{Root Container.Numeric Label.plus5},"255,172,71","217,0,0"))

I think this would make it easy to copy the indicator and just edit the SP and PV to point to the next tags.

There’s probably refinements but its 11pm!

I believe you could do it with 1 custom property and an expression using nested if statements.

In the expression, max_value is the largest possible value of the tag.

# Psuedo-code for the expression
if( (abs(value - setpoint) / max_value) > .05, 'C',  if( (abs(value - setpoint) / max_value) > .03, 'B', 'A' ) )

This expression will return either A, B or C for your custom property. I would change the return values to 3, 2 or 1 if I was implementing it.

Use the value of your custom property in the style customizer to set the colors and you’re done.

You might have to use toFloat() to be sure to get a decimal value.

ONE Custom Property to hold the amount of error :wink: :

abs({Root Container.Process.value}-{Root Container.Setpoint.value})/{Root Container.Setpoint.value}*100

If they need to be lopsided above vs. below, then take out the ‘abs’ portion at the begining:

({Root Container.Process.value}-{Root Container.Setpoint.value})/{Root Container.Setpoint.value}*100

The Style Customizer can handle the rest.

Since I can’t currently upload anything to the forum, here’s a Dropbox link:
https://www.dropbox.com/s/4blw0kear3i5j9a/colorChanger.vwin