How to change Bar chart color based on value

Ignition newbie here.

I am working on a production output monitoring display here using bar chart and I want that
my bar color will change based on it’s value like if it did not reach the target.

I’ve tried this script in which I found in another topic here but it doesn’t seem to be working for me.
I attached this script in the Extension Functions \ configureChart

from org.jfree.chart.renderer.category import BarRenderer
from java.awt import Color
class myBarRenderer(BarRenderer):
def getItemPaint(self, row, column):
v = chart.getCategoryPlot().getDataset().getValue(row, column)
if v > 30:
return Color.green
else:
return Color.red
plot = chart.getCategoryPlot()
plot.setRenderer(myBarRenderer())

can somebody here guide me if there is an easier way to do this.

The script you posted should work; the only suspicion I have is about the chart itself. Are you using the classic chart, and if so, are you using a bar type renderer on it? Also, are you receiving any actual error, or is the code just apparently not working? Try looking in the output console (Ctrl + Shift + C in the Designer) to see if any error messages or warnings are being logged.

Slurpee,

If you are using the Bar Chart component, you do not need that script - just use the getBarColor extension function:

1 Like

@PGriffith @anna
Thank you so much for your reply, I am actually using the easy chart but I was able to make it work in a different way.
I have used 2 different series by adding conditions in my query.
I will try to use this method on my next project or if I need to make some changes again on this project.

Thank you very much. solution very simple, but very efficient.