Problem getBarColor


I have a problem with the Bar Chart component. We are using the extended function getBarColor
We would like to have a dynamic target based on a Tag. So the Tag should be dynamic and we have a property defined in the window that is called ID_MACHINE.
When we try to get the string value we have the error “Illegal character {”. The same string value ‘{Root Container.ID_MACHINE}’ is used in the query.

This is our code:

from java.awt import Color
machine = ‘{Root Container.ID_MACHINE}’

val =‘VisionTag/’+machine+’/TARGET_VALUE’).getValue()
if value > val:
return Color.GREEN
return Color.RED

Could you please help us? How can we do to set dynamic Tag name?


The string substitution of properties and tags using curly braces doesn’t work in scripts. You must use jython property access syntax or*() functions, respectively. Something like self.parent.ID_MACHINE. Consider adding another custom property that uses an indirect tag binding to retrieve the target value outside of the getBarColor() method. That will eliminate the repeated tag reads for each bar to display. Reading a property is dramatically faster.

1 Like

You can’t use the curly brace ({}) reference syntax in scripting. So, to achieve the same result within the getBarColor extension function, you’ll need to start from the self variable that’s provided - which is a reference to the bar chart component itself. From there, go up the component hierarchy to the root container, and read your custom parameter:
machine = self.parent.ID_MACHINE

1 Like