# Report Bar Chart Color by Axis label

**URL:** <https://forum.inductiveautomation.com/t/report-bar-chart-color-by-axis-label/44661>\
**Category:** Ignition\
**Tags:** reporting\
**Created:** [March 18, 2021, 10:51pm UTC](https://forum.inductiveautomation.com/t/report-bar-chart-color-by-axis-label/44661 "2021-03-18T22:51:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dojeda](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@dojeda](https://forum.inductiveautomation.com/u/dojeda)\
**Post date:** [March 18, 2021, 10:51pm UTC](https://forum.inductiveautomation.com/t/report-bar-chart-color-by-axis-label/44661/1 "2021-03-18T22:51:12Z")

</div>

Hi there,  
Need some guidance, I'm populating a Bar chart in the report by a SQL Query, and I tried the Script in the bar chart in the Reports to change the color of the Segments of the Bar depending on the Value, But I would like Change the color depending on the Category label:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/4/64d7eca74c150a7b12dbc60be1d7ba19079e7e27.png)

I want the bar "Starved" to be always yellow, "Blocked" Blue, "Cycling" Green, "InFault" Red and so on.  
What will be the correct script to check that??, this is the script I tried to change the colours of the bars, depending on Value:

```
from java.awt import Color
a = 1
    #gets the underlying dataset in the chart
ds = chart.getPlot().getDataset()
print ds.columnCount
    # 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:** ![Paulo\_Custodio](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paulo_custodio/32/56599_2.png) [@Paulo\_Custodio](https://forum.inductiveautomation.com/u/Paulo_Custodio)\
**Post date:** [February 1, 2024, 10:38pm UTC](https://forum.inductiveautomation.com/t/report-bar-chart-color-by-axis-label/44661/2 "2024-02-01T22:38:48Z")

</div>

I need to do something similar. Any help?

---

<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:** [February 2, 2024, 12:57am UTC](https://forum.inductiveautomation.com/t/report-bar-chart-color-by-axis-label/44661/4 "2024-02-02T00:57:18Z")

</div>

> [@Transistor](#):
>
> seems to be Vision but isn't tagged.

Reports are neither Vision nor Perspective. They are independent. There's just some overlap with JFreeCharts.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 2, 2024, 1:49am UTC](https://forum.inductiveautomation.com/t/report-bar-chart-color-by-axis-label/44661/5 "2024-02-02T01:49:39Z")

</div>

Gahh! I missed the first word in the title. Thanks. I've added the `reporting` tag.

---

<div class="post-metadata">

**Author:** ![Thomas\_Maldonado](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thomas_maldonado/32/57927_2.png) [@Thomas\_Maldonado](https://forum.inductiveautomation.com/u/Thomas_Maldonado)\
**Post date:** [February 9, 2024, 5:15pm UTC](https://forum.inductiveautomation.com/t/report-bar-chart-color-by-axis-label/44661/6 "2024-02-09T17:15:31Z")

</div>

Came across this today and sharing the script I wrote for my situation. I have a stacked bar chart with all the state durations of stations within a line.

```python
from java.awt import Color
plot = chart.getCategoryPlot()
lst_States = plot.dataset.getRowKeys()

# Set the color of each state in stacked bar chart
categoryRenderer = plot.getRenderer()
for i in range(len(lst_States)):
    state = lst_States[i]

    # Converts the RGB color for java.awt.Color
    rgbColor = gl.style.getColorOfState(state)
    finalColor = Color(rgbColor[0], rgbColor[1], rgbColor[2])

    # Update the color for the state
    categoryRenderer.setSeriesPaint(i, finalColor)

```
