Color depending of value

What is the best method to coloring a Numeric Label or Text Field based on values/expression?

I have 3 options to set the color:

first color - if the value <x

second color - if the value >=x and <=x*1.10

third color - if the value is >x*1.10

thanks

{A84E227F-B366-4EF4-A8E2-9EB34F22ED75}

Use an Expression binding:

if({value} < {x},
	'blue',
	if({value} > {x} * 1.10,
		'red',
		'green'
	)
)

Thank you, do you know if this is the best way?

Now , if I have the same logic for multiple controls, can I in some way use one global function from all the controls to do this logic? so if the logic changes I can do it only in one place instead of each control…

Well, you could bind the 1.10 to a custom property instead of hardwiring it (as well as the colors themselves). Otherwise I would just point you to something I wish I had known about much sooner:

You could also create a library function and call it with runScript() if you want a single point of change that is more flexible. It won’t execute as quickly, but for something as simple as this the difference would probably not be noticeable. I’m all for code reuse when practical, but in Ignition I try to use pure Expressions as much as possible for efficient, responsive displays.

1 Like

Use the style customizer:

You can 'back up' the styles dataset in a (optionally: client) tag and bind all of your components with common styles to that common tag.
The style customizer offers an easy GUI way to manage multiple types of appearance changes in one go without the overhead of scripting.

5 Likes

thank you