Customizing the Report Bar Chart using scripting

I've created the following report using a Bar Chart:

However, I'd like to customize it so that the color changes based upon whether or not the value exceeds a target value for each item. I added the following code:
from java.awt import Color
from org.jfree.chart.renderer.category import BarRenderer

class myBarRenderer(BarRenderer):
	def getItemPaint(self, row, column):
		tgt = data["Targets"].getValueAt(column, "Target")
		act = data["Actuals"].getValueAt(column, "Actual")
		if act < tgt:
			return Color(64,108,160)
			return Color(255,71,71) #Color.
plot = chart.getCategoryPlot()

which changed the report to look like this:

The customized chart displays the colors correctly but a couple of issues have appeared. 1st, the bars changed to 3D renderings, and 2nd, the value labels disappeared. The 1st issue isn't really a problem, I just don't like it as much as the 2D version. I've scoured the web looking for a solution to the 2nd issue but have not had any luck. Any help would be greatly apprecieated.

Disclaimers: I never used vision, I never used jfree, I haven't coded in Java for years, and I can't test any of this.

First thing I'd do is try to find the bar renderer class used by default by ignition, and subclass this instead of jfree's BarRenderer.

If you can't, you might have some success going back to the 2d models by fiddling with the attributes of the parent class (I suppose you can override them in the child class), which you can find here:
Its source might be helpful:
Or maybe it's own parent:

The gradient transformer might be what you need to handle the 3d effect, and there are methods that concern the labels, which might be what you need to bring them back.

Whatever else you do with BarRenderer, you should be copying the settings of the renderer that was already there into your new renderer instance. That you aren't is probably why the report looks so different.

I encountered this exact problem here in the forum a little while back. Here was the solution:

Thanks everyone!

1 Like