# Changing Report Table Text Colour Based on Value

**URL:** <https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [June 5, 2018, 6:35pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306 "2018-06-05T18:35:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![magnann](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@magnann](https://forum.inductiveautomation.com/u/magnann)\
**Post date:** [June 5, 2018, 6:35pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/1 "2018-06-05T18:35:21Z")

</div>

I am currently creating several reports with tables and would like to be able to change the text colour based on the value (above or below a certain numeric value I would like to change the colour from black to red). I see text colour is a property, but see no way to bind/script the colour. I only see a way to manually change the colour in the Property Inspector. Is there any way to modify text colour based on parameters such as text value? I’m not even sure it’s even possible due to the text being a string and not a numeric value.

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [June 5, 2018, 6:47pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/2 "2018-06-05T18:47:31Z")

</div>

Check out [https://docs.inductiveautomation.com/display/DOC79/Keychain+Expressions](https://docs.inductiveautomation.com/display/DOC79/Keychain+Expressions)

Particularly the section on conditional keychain expressions:

```auto
#If the value of the "myValue" key is greater than 5, a blue color will be returned. Otherwise, a green color will be used.
@myValue>5?"blue":"green"@

```

---

<div class="post-metadata">

**Author:** ![magnann](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@magnann](https://forum.inductiveautomation.com/u/magnann)\
**Post date:** [June 5, 2018, 7:15pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/3 "2018-06-05T19:15:37Z")

</div>

Thank you for the help!

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [January 27, 2020, 1:14pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/4 "2020-01-27T13:14:00Z")

</div>

Hi,

Is it possible to put a RGB or Hex color in keychain expression ?  
I would like to create a dynamic fill color.

Thanks

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [June 26, 2023, 8:49am UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/6 "2023-06-26T08:49:19Z")

</div>

Do you have a solution for my question ?  
I can't put a RGB color or an hex color dynamically in a property.  
I have a variable like :

```auto
[{"title":xxx,"color":"#FF6F00"},{"title":xxx,"color":"#FFC107"},..]

```

I put my variable in a table.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/9184f37095f49906e0ebce2727d8fec45443f968.png)  
For each row I would like to dynamically apply a color using the coresponding key.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/7/e754fb5c7713f64fac2e1ed757fdd9cfaa82ac04.png)

It doesn't work. I tried :

```auto
[{"title":xxx,"color":(255,111,0)},{"title":xxx,"color":(255,193,7)},..]

```

```auto
[{"title":xxx,"color":"255,111,0"},{"title":xxx,"color":"255,193,7"},..]

```

```auto
[{"title":xxx,"color":system.gui.color("#FF6F00")},{"title":xxx,"color":system.gui.color("#FFC107")},..]

```

The last one shows me :  
WARN: Error invoking script.Traceback (most recent call last):  
File "function:updateData", line 11, in updateData  
AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'gui'

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 26, 2023, 11:45am UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/7 "2023-06-26T11:45:20Z")

</div>

> [@flavien](#):
>
> object has no attribute 'gui'

You simply cannot use `system.gui.*` in gateway scope (nor in Perspective). At all. You will need to construct what you need from `java.awt.Color`.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [June 26, 2023, 12:01pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/8 "2023-06-26T12:01:53Z")

</div>

How can I use it ?

```auto
from java.awt import Color
[{"title":xxx,"color":Color(255,111,0)},{"title":xxx,"color":Color(255,193,7)},..]

```

This doesn't work

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 26, 2023, 12:07pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/9 "2023-06-26T12:07:10Z")

</div>

I suppose I should have linked to it: [java.awt.Color](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/Color.html)

You would use one of the Constructors or one of the predefined fields to obtain the color object you need.

```auto
from java.awt import Color

someColor = Color(red, green, blue)
anotherColor = Color(red, gree, blue, alpha)

```

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [June 26, 2023, 12:20pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/10 "2023-06-26T12:20:51Z")

</div>

It's not working too.  
🤷  
May be the report module is the problem.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 26, 2023, 12:29pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/11 "2023-06-26T12:29:42Z")

</div>

> [@flavien](#):
>
> It's not working too.

Are you trying to put any of this directly in a keychain expression? If so, no, it won't work, because jython is not available there. You need to do this sort of thing in the data section of your report, transforming your source data to have the appropriate colors in the row data where needed. Typically with a script data source.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [June 26, 2023, 12:32pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/12 "2023-06-26T12:32:16Z")

</div>

My variable containing colors is generated in the data source section. In the designer I just call my variable like I described in my first post.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 26, 2023, 12:35pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/13 "2023-06-26T12:35:37Z")

</div>

> [@flavien](#):
>
> My variable containing colors is generated in the data source section.

That's not enough. You have to apply that variable to the row data in the data source section, too.

---

<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:** [June 26, 2023, 4:43pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/14 "2023-06-26T16:43:14Z")

</div>

Performance would be _terrible_ compared to inserting it into the data source directly, but I'm pretty sure you could do dynamic colors in a keychain with a well formatted rtf() declaration:  
[https://www.reportmill.com/support/keychains.pdf#Page:8](https://www.reportmill.com/support/keychains.pdf#Page:8)  
[http://www.pindari.com/rtf1.html](http://www.pindari.com/rtf1.html)

Seriously though, just use the script data source.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [June 27, 2023, 1:25pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/15 "2023-06-27T13:25:50Z")

</div>

It works !  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/b/7be257e49ef829c82911e685afcdb08860508f26.png)  
You don't have to write "@" in dynamic key. 🤷

---

<div class="post-metadata">

**Author:** ![Ryan\_Shaw](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Ryan\_Shaw](https://forum.inductiveautomation.com/u/Ryan_Shaw)\
**Post date:** [January 3, 2024, 8:52pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/16 "2024-01-03T20:52:56Z")

</div>

I am also trying to add background color dynamically to the rows being returned in my report. I tried setting up a script data source like such:

```auto
from java.awt import Color	
	
rawResults = data['SparePartsByMasterPart'].getCoreResults()
hasSpareParts = rawResults.getColumnAsList(rawResults.getColumnIndex('HasSpareParts'))
legendColor = [Color(255,204,204) if val is None else Color(240,240,240) for val in hasSpareParts]
newDS = system.dataset.addColumn(rawResults, legendColor, 'LegendColor', Color)
data['SparePartsWithColor'] = newDS

```

I get back the error

> WARN: Error invoking script.Traceback (most recent call last):  
> File "function:updateData", line 8, in updateData  
> TypeError: can't put element of type color in dataset."

Am I formatting this incorrectly, or is this related to the bug being discussed in [Can't use Color Datatype in Dataset tag anymore, error: 'Invalid DataType for Dataset.' - #7 by matthew.byars](https://forum.inductiveautomation.com/t/cant-use-color-datatype-in-dataset-tag-anymore-error-invalid-datatype-for-dataset/54978/7)? I am on 8.1.23.

---

<div class="post-metadata">

**Author:** ![Ryan\_Shaw](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Ryan\_Shaw](https://forum.inductiveautomation.com/u/Ryan_Shaw)\
**Post date:** [January 3, 2024, 10:02pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/17 "2024-01-03T22:02:48Z")

</div>

I was able to get the colors I needed by using a dynamic key on the cell fill background and referencing [toColor - Ignition User Manual 7.9 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC79/toColor) and using spaces instead of camel case for string literals. Ex. my key expression on "Fill Color" is

```auto
HasSpareParts==-1?"pink":"slate gray"

```

In my query data source I had to cast HasSpareParts to an integer because none of these comparisons, HasSpareParts == True, true, False, false, 0, 1, none, None, null, Null, and NULL, were working when I had it as a bit.

Using a script data source would still be much more convenient and readable, so I hope I can get an answer to that.

---

<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 3, 2024, 10:05pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/18 "2024-01-03T22:05:43Z")

</div>

> [@Ryan\_Shaw](#):
>
> I am on 8.1.23.

Upgrade, we fixed the issue with colors in datasets.

---

<div class="post-metadata">

**Author:** ![Ryan\_Shaw](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@Ryan\_Shaw](https://forum.inductiveautomation.com/u/Ryan_Shaw)\
**Post date:** [January 3, 2024, 10:18pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/19 "2024-01-03T22:18:55Z")

</div>

Hi PGriffith

Thanks! I'll do that.

---

<div class="post-metadata">

**Author:** ![hw79](https://avatars.discourse-cdn.com/v4/letter/h/838e76/32.png) [@hw79](https://forum.inductiveautomation.com/u/hw79)\
**Post date:** [July 31, 2024, 12:45pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/20 "2024-07-31T12:45:24Z")

</div>

I'm trying to use the conditional keychain to change the background colors, but it doesn't seem to be evaluating correctly.

This is the key I'm using: `RegionAVG<Criteria1?"red":RegionAVG<Criteria2?"yellow":RegionAVG>=Criteria3?"green"`

All of my results seem to be evaluating true for the first condition, which they are not.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/0645e4dea9e189ed4e6df027fce1ea4322e50f97.png)

The [documentation](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/reporting/report-design/data-keys/keychain-expressions#conditional-keychain-example) shows `myValue<5?"blue":"green"` as the first example, then later wraps the compound evaluation with `@` like this: `@myValue>10?"red":myValue>5?"blue":"green"@`. Wrapping seems to break it.

Also of note, I don't see an example where the value is evaluated against another data key.

---

<div class="post-metadata">

**Author:** ![Tyler\_Judkins](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@Tyler\_Judkins](https://forum.inductiveautomation.com/u/Tyler_Judkins)\
**Post date:** [February 13, 2025, 11:14pm UTC](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306/21 "2025-02-13T23:14:57Z")

</div>

@hw79 where you able to figure out how to compare two data keys? I just hit this problem.

[Next page](https://forum.inductiveautomation.com/t/changing-report-table-text-colour-based-on-value/18306.md?page=2)
