Change Pen Color based on its Tag's Value

I have a chart that I would like to change the color of its pen to Red/Yellow/Green based on its tag value.
Is there anyway to do this? or is there other methods to accomplish this function?
Thanks,
Sam


Charts are a bit tricky, as you can’t add custom properties. But you can achieve this with a custom property on the chart’s parent (usually the root container). Create it with data type “Color”, and bind it to an expression that will generate the colors you want, like so:

if({[System]Gateway/Performance/Memory Utilization}>0.1, color(255,0,0), color(0,255,0))
Then monitor this property for changes, writing into the chart’s pen definition when you have a new value, like so:

if event.propertyName=='PenColor': if (event.newValue!=event.oldvalue): chart = event.source.getComponent("Chart") chart.tagPens = system.dataset.setValue(chart.tagPens, 0, "color", event.newValue)
Replace the “0” in setValue() with the row index for the pen you want to have this dynamic color. The extra check to make sure it’s a new color keeps the chart from blinking every time the value of interest changes.