# \[IGN-1566\] Perspective - Color function not returning a usable value

**URL:** <https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001>\
**Category:** Ignition Early Access\
**Created:** [November 21, 2018, 7:28pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001 "2018-11-21T19:28:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [November 21, 2018, 7:28pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/1 "2018-11-21T19:28:06Z")

</div>

I attempted to bind a backgroundColor property to an expression that was just the color() expression function to quickly get a color from three values. However, this doesn't actually make the correct color show up as the background. In the little preview color square next to the backgroundColor value (that reads 'java.awt.Color[r=44,g=55,b=66]'), the color is correct, that just doesn't make it to the actual background.

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a8d365ddd6dec0cd703be77869fff30125825809.png)

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/9c09ff9462a56ceb1e9e4e3f69a70baff477f11e.png)

The red in the example there is from when I clicked the color preview square and picked red, then tried to refresh the expression binding. When put into run/preview mode, it switches to a white background, or whatever the default background color is.

This is on b2018112110. Reproduction can be done on any component, I obviously use a slider component and its backgroundColor property.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 21, 2018, 7:52pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/2 "2018-11-21T19:52:20Z")

</div>

You’re very right. I’ll open a new ticket for this right now.

That expression is typically used for Vision components, which expect a java.awt.Color Object, whereas Perspective uses Hex colors throughout.

As you’re directly binding to non-interpolated (never-changing) values, consider providing the String Hex equivalent ‘#2C3742’ for the property value.

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [November 21, 2018, 8:31pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/3 "2018-11-21T20:31:48Z")

</div>

I figured, and I hope it won’t be too much to adapt it to Perspective use somehow. And that was just an example, I was testing a couple sliders making up a color for something else, but still easy to format it into the hex string like you mentioned.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 21, 2018, 10:02pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/4 "2018-11-21T22:02:17Z")

</div>

As a workaround, you can add a transform if you need to use color():

```python
	colorIn = value
	hexVal = '#' + hex(colorIn.getRed()*65536 + colorIn.getGreen()*256 + colorIn.getBlue())[2:]
	return hexVal

```

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [February 4, 2022, 4:08am UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/5 "2022-02-04T04:08:04Z")

</div>

Actually, I tried this and it doesn't work for colors with no Red or Green components in it. That's because the hex function doesn't pad the value with leading zeros. Instead, I would suggest using this (I also added alpha):

> hexVal = '#%02x%02x%02x%02x' % (colorIn.getRed(),colorIn.getGreen(),colorIn.getBlue(),colorIn.getAlpha())

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [November 17, 2023, 12:34pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/6 "2023-11-17T12:34:06Z")

</div>

Is there an update, this seems still the case?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [November 19, 2023, 5:06pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/7 "2023-11-19T17:06:25Z")

</div>

No, it has not been implemented yet. I've updated the internal ticket to reflect there is continued interest in making these changes.

---

<div class="post-metadata">

**Author:** ![n099y](https://avatars.discourse-cdn.com/v4/letter/n/258eb7/32.png) [@n099y](https://forum.inductiveautomation.com/u/n099y)\
**Post date:** [February 24, 2025, 1:16am UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/8 "2025-02-24T01:16:16Z")

</div>

Still not working ?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 24, 2025, 3:43pm UTC](https://forum.inductiveautomation.com/t/ign-1566-perspective-color-function-not-returning-a-usable-value/21001/9 "2025-02-24T15:43:14Z")

</div>

No, we have not implemented this yet.
