# Reporting bar chart colors

**URL:** <https://forum.inductiveautomation.com/t/reporting-bar-chart-colors/11517>\
**Category:** Ignition\
**Created:** [April 15, 2016, 10:41pm UTC](https://forum.inductiveautomation.com/t/reporting-bar-chart-colors/11517 "2016-04-15T22:41:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![erick](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@erick](https://forum.inductiveautomation.com/u/erick)\
**Post date:** [April 15, 2016, 10:41pm UTC](https://forum.inductiveautomation.com/t/reporting-bar-chart-colors/11517/1 "2016-04-15T22:41:46Z")

</div>

This is an example to make your bar chart colors customizable using the JFree Chart API in JYTHON.  
This is executed under the chart properties =\> edit script.

```
from java.awt import Color
a = 1
    #gets the underlying dataset in the chart
ds = chart.getPlot().getDataset()
#print ds.rowCount
    # gets the plot
plot = chart.getCategoryPlot()
    #gets the Barrenderer object
renderer = plot.getRenderer()
    #Loop Through dataset and check value and assign series colors
for row in range(ds.rowCount):
	print row
	value = float(ds.getValue(row, 0))
	print value
	
	if value >= 100.0:
		print 'Row %d should be green'%row
		renderer.setSeriesPaint(row, Color.GREEN)
	if value <= 99.9 and value >= 88.0:
		print 'Row %d should be yellow'%row
		renderer.setSeriesPaint(row,Color.YELLOW)
	if value <= 87.9:
		print 'Row %d should be red'%row
		renderer.setSeriesPaint(row,Color.RED)
	else:
		a = 0
```

---

<div class="post-metadata">

**Author:** ![hp1](https://avatars.discourse-cdn.com/v4/letter/h/34f0e0/32.png) [@hp1](https://forum.inductiveautomation.com/u/hp1)\
**Post date:** [November 22, 2016, 3:44pm UTC](https://forum.inductiveautomation.com/t/reporting-bar-chart-colors/11517/2 "2016-11-22T15:44:06Z")

</div>

This sets the series colors. It doesn’t set the color based on the value of the same series. I am trying to change the color based on the value of the bar in the same series. Any suggestion…thanks

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [November 22, 2016, 4:49pm UTC](https://forum.inductiveautomation.com/t/reporting-bar-chart-colors/11517/3 "2016-11-22T16:49:04Z")

</div>

[code] 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 < 70:
			return Color.blue
		else:
			return Color.red

plot = chart.getCategoryPlot()
plot.setRenderer(myBarRenderer())[/code]
```

---

<div class="post-metadata">

**Author:** ![hp1](https://avatars.discourse-cdn.com/v4/letter/h/34f0e0/32.png) [@hp1](https://forum.inductiveautomation.com/u/hp1)\
**Post date:** [November 22, 2016, 6:42pm UTC](https://forum.inductiveautomation.com/t/reporting-bar-chart-colors/11517/4 "2016-11-22T18:42:28Z")

</div>

[quote=“jpark”][code] 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 < 70:
			return Color.blue
		else:
			return Color.red

plot = chart.getCategoryPlot()
plot.setRenderer(myBarRenderer())[/code][/quote]

```

Thank you! It works great!

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [April 3, 2020, 8:54am UTC](https://forum.inductiveautomation.com/t/reporting-bar-chart-colors/11517/5 "2020-04-03T08:54:48Z")

</div>

Hi,

It didn’t work for me in a bar chart script in report module. (ignition 7.9.9)  
My code below in def configureChart(data,chart) :

```auto
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 < 0:
				return Color.green
			else:
				return Color.red
	
	plot = chart.getCategoryPlot()
	plot.setRenderer(myBarRenderer())

```

Error is :  
File “function:configureChart”, line 13, in configureChart  
java.lang.ClassCastException: java.lang.ClassCastException: org.jfree.chart.plot.XYPlot cannot be cast to org.jfree.chart.plot.CategoryPlot

Thanks
