# Expression Help with Fill Colors

**URL:** <https://forum.inductiveautomation.com/t/expression-help-with-fill-colors/31433>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [January 20, 2020, 6:33pm UTC](https://forum.inductiveautomation.com/t/expression-help-with-fill-colors/31433 "2020-01-20T18:33:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![regan.lewis](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/regan.lewis/32/34945_2.png) [@regan.lewis](https://forum.inductiveautomation.com/u/regan.lewis)\
**Post date:** [January 20, 2020, 6:33pm UTC](https://forum.inductiveautomation.com/t/expression-help-with-fill-colors/31433/1 "2020-01-20T18:33:53Z")

</div>

Hello Everyone,

I am struggling with trying to select a fill color based off of an expression.

Ultimately, I want a Numeric Label’s “Background Fill” to change color based off conditions. The tags that I need are a part of my Motor UDT.  
I was able to accomplish this easily in FactoryTalk but haven’t been able to in Ignition.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/99bde160eb8eb153371fee7f97078704e820a56a.png)  
Here’s the actual expression from FA:  
IF {[PLC\_100\_1\_1]C\_113\_20.Running} AND {[PLC\_100\_1\_1]C\_113\_20.Alarm}  
THEN 3  
ELSE IF {[PLC\_100\_1\_1]C\_113\_20.Running} AND {[PLC\_100\_1\_1]C\_113\_20\_Current\_Alarm}  
THEN 3  
ELSE If {[PLC\_100\_1\_1]C\_113\_20.Running} AND NOT {[PLC\_100\_1\_1]C\_113\_20.Alarm} AND NOT {[PLC\_100\_1\_1]C\_113\_20\_Current\_Alarm}  
THEN 1  
ELSE 0

If someone could give me some guidance, it would be appreciated.  
Thank you

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [January 20, 2020, 6:54pm UTC](https://forum.inductiveautomation.com/t/expression-help-with-fill-colors/31433/2 "2020-01-20T18:54:41Z")

</div>

We do something similar with out object.

The code is fairly easy. You will be using the toColor expression function so go read up on that.

Basically the code looks like this:

```auto
if(
    {Running} && {Alarm},
    toColor('red'), (Number 3 Color Selection from FTView)
    if(
        {Running} && {CurrentAlarm},
        toColor('red'), (Number 3 Color Selection from FTView)
        if(
            {Running} && ! ({Alarm} || {CurrentAlarm}),
            toColor('green'), (Number 1 Color Selection from FTView)
            toColor('gray') (Number 0 Color Selection from FTView)
        )
    )
)

```

Basically it’s a series of if then statements to determine the color.

---

<div class="post-metadata">

**Author:** ![regan.lewis](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/regan.lewis/32/34945_2.png) [@regan.lewis](https://forum.inductiveautomation.com/u/regan.lewis)\
**Post date:** [January 23, 2020, 4:21pm UTC](https://forum.inductiveautomation.com/t/expression-help-with-fill-colors/31433/3 "2020-01-23T16:21:01Z")

</div>

Thank you for the help bschroeder; it worked perfectly. I still find this statement structure confusing… Do you have any recommendations for sources that can help me?

Also, would it possible to add blinking animations in conjuncture with the colors?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 23, 2020, 4:39pm UTC](https://forum.inductiveautomation.com/t/expression-help-with-fill-colors/31433/4 "2020-01-23T16:39:34Z")

</div>

Another option, that I find a bit easier to reason about (and extend, down the road) is to pair the [`binEnum`](https://docs.inductiveautomation.com/display/DOC80/binEnum) expression function with the style customizer (which also lets you add blinking and easily change colors).

- Make a custom property that’s an integer type.

- Add an expression to it; adopting from @bschroeder, it’d look like this:

- Open the [Style Customizer](https://docs.inductiveautomation.com/display/DOC80/Vision+Component+Customizers#VisionComponentCustomizers-StyleCustomizer) on your component. Select your newly created custom property as the ‘driving property’, and choose whatever aspects of the component (foreground color, background color, font, etc) you want to change based on the driving property.

- Set up your different colors for the different states in the rows below.

- If you need dynamic colors, you can separately add a ‘Cell Update Binding’ to the ‘Styles’ dataset property on the component.

An advantage to this approach is ‘separation of concerns’ - the logic for which color to use is separate from the logic of what ‘state’ the component should be in.

---

<div class="post-metadata">

**Author:** ![regan.lewis](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/regan.lewis/32/34945_2.png) [@regan.lewis](https://forum.inductiveautomation.com/u/regan.lewis)\
**Post date:** [January 24, 2020, 5:53pm UTC](https://forum.inductiveautomation.com/t/expression-help-with-fill-colors/31433/5 "2020-01-24T17:53:34Z")

</div>

Thank you for the help, it worked great!
