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.
Check out https://docs.inductiveautomation.com/display/DOC79/Keychain+Expressions
Particularly the section on conditional keychain expressions:
#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"@
Thank you for the help!
Hi,
Is it possible to put a RGB or Hex color in keychain expression ?
I would like to create a dynamic fill color.
Thanks
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 :
[{"title":xxx,"color":"#FF6F00"},{"title":xxx,"color":"#FFC107"},..]
I put my variable in a table.
For each row I would like to dynamically apply a color using the coresponding key.
It doesn't work. I tried :
[{"title":xxx,"color":(255,111,0)},{"title":xxx,"color":(255,193,7)},..]
[{"title":xxx,"color":"255,111,0"},{"title":xxx,"color":"255,193,7"},..]
[{"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'
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
.
How can I use it ?
from java.awt import Color
[{"title":xxx,"color":Color(255,111,0)},{"title":xxx,"color":Color(255,193,7)},..]
This doesn't work
I suppose I should have linked to it: java.awt.Color
You would use one of the Constructors or one of the predefined fields to obtain the color object you need.
from java.awt import Color
someColor = Color(red, green, blue)
anotherColor = Color(red, gree, blue, alpha)
It's not working too.
May be the report module is the problem.
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.
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.
That's not enough. You have to apply that variable to the row data in the data source section, too.
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
http://www.pindari.com/rtf1.html
Seriously though, just use the script data source.
It works !
You don't have to write "@" in dynamic key.
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:
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? I am on 8.1.23.
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 and using spaces instead of camel case for string literals. Ex. my key expression on "Fill Color" is
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.
Upgrade, we fixed the issue with colors in datasets.
Hi PGriffith
Thanks! I'll do that.
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.
The documentation 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.