# Customizing the Report Bar Chart using scripting

**URL:** <https://forum.inductiveautomation.com/t/customizing-the-report-bar-chart-using-scripting/69089>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [January 27, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/customizing-the-report-bar-chart-using-scripting/69089 "2023-01-27T13:48:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![naturesbeast](https://avatars.discourse-cdn.com/v4/letter/n/d07c76/32.png) [@naturesbeast](https://forum.inductiveautomation.com/u/naturesbeast)\
**Post date:** [January 27, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/customizing-the-report-bar-chart-using-scripting/69089/1 "2023-01-27T13:48:30Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/1/414d48419774dbb06cd49e3904d4ce3dad135691.png)  
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) #Color.blue
		else:
			return Color(255,71,71) #Color.
			
plot = chart.getCategoryPlot()
plot.setRenderer(myBarRenderer())</code>

```
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.`

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 27, 2023, 2:56pm UTC](https://forum.inductiveautomation.com/t/customizing-the-report-bar-chart-using-scripting/69089/2 "2023-01-27T14:56:03Z")

</div>

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:  
[https://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/renderer/category/BarRenderer.html](https://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/renderer/category/BarRenderer.html)  
Its source might be helpful:  
[https://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/renderer/category/BarRenderer-source.html](https://www.jfree.org/jfreechart/api/gjdoc/org/jfree/chart/renderer/category/BarRenderer-source.html)  
Or maybe it's own parent:  
[https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.html](https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/category/AbstractCategoryItemRenderer.html)

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 27, 2023, 4:16pm UTC](https://forum.inductiveautomation.com/t/customizing-the-report-bar-chart-using-scripting/69089/3 "2023-01-27T16:16:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 27, 2023, 7:24pm UTC](https://forum.inductiveautomation.com/t/customizing-the-report-bar-chart-using-scripting/69089/4 "2023-01-27T19:24:44Z")

</div>

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

> [@Report chart hides bar value labels when update BarRenderer](https://forum.inductiveautomation.com/t/report-chart-hides-bar-value-labels-when-update-barrenderer/64682/2):
>
> This is doable, but you have to set the label generator to your custom renderer and then set its visibility to true. You will get the result you are looking for if you change your commented code to look like this: class CustomRenderer(BarRenderer): def getItemPaint(self, row, column): cntValue = chart.getCategoryPlot().getDataset().getValue(row, column) inRange = cntValue \> mTarget-chartValueLimiter and cntValue \< mTarget+chartValueLimiter return Color.green if inRange else Color.re…

---

<div class="post-metadata">

**Author:** ![naturesbeast](https://avatars.discourse-cdn.com/v4/letter/n/d07c76/32.png) [@naturesbeast](https://forum.inductiveautomation.com/u/naturesbeast)\
**Post date:** [January 29, 2023, 4:12pm UTC](https://forum.inductiveautomation.com/t/customizing-the-report-bar-chart-using-scripting/69089/5 "2023-01-29T16:12:23Z")

</div>

Thanks everyone!
