# Change each bar width in histogram chart

**URL:** <https://forum.inductiveautomation.com/t/change-each-bar-width-in-histogram-chart/66847>\
**Category:** Ignition\
**Tags:** vision, scripting\
**Created:** [November 23, 2022, 11:49am UTC](https://forum.inductiveautomation.com/t/change-each-bar-width-in-histogram-chart/66847 "2022-11-23T11:49:56Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [November 25, 2022, 9:54am UTC](https://forum.inductiveautomation.com/t/change-each-bar-width-in-histogram-chart/66847/8 "2022-11-25T09:54:26Z")

</div>

@prasath.t - It certainly looks like this is possible. To get you started, below is an example of how to extend [the BarRenderer class](https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/category/BarRenderer.html) using the _ **configureChart extension function** _. In the example, I use a variable called barStartingLocation to set the beginning point of each bar, and then I use a barScaleParameter to adjust the width of the bar. For both variables, I have just stuck in numbers to illustrate the effect, but it shouldn't be too difficult to develop a way to loop through each row in the chart's dataset and dynamically adjust these variables. I have also added code to change the color of each bar to make it easier to see what is actually being accomplished.

Here is the code:

```auto
	from org.jfree.chart.renderer.category import BarRenderer, StandardBarPainter
	from java.awt import Color
	chart.setTitle("Histogram")
	class DynamicWidthRenderer(BarRenderer):
		def	calculateBarW0(BarRenderer, plot, orientation, dataArea, domainAxis, state, row, column):
			if column == 0:
				barStartingLocation = 82
				barScaleParameter = 100
				dataArea.width = barScaleParameter
				BarRenderer.calculateBarWidth(plot, dataArea, 0, state)
				return barStartingLocation
			elif column == 1:
				barStartingLocation = 100
				barScaleParameter = 600
				dataArea.width = barScaleParameter
				BarRenderer.calculateBarWidth(plot, dataArea, 0, state)
				return barStartingLocation
			elif column == 2:
				barStartingLocation = 212
				barScaleParameter = 2600
				dataArea.width = barScaleParameter
				BarRenderer.calculateBarWidth(plot, dataArea, 0, state)
				return barStartingLocation
			else:
				barStartingLocation = 699
				barScaleParameter = 867.030849457
				dataArea.width = barScaleParameter
				BarRenderer.calculateBarWidth(plot, dataArea, 0, state)
				return barStartingLocation
		def getItemPaint(BarRenderer, row, column):
			if column == 0:
				return Color.orange
			elif column == 1:
				return Color.gray
			elif column == 2:
				return Color.red
			else:
				return Color.blue
	chart.getCategoryPlot().setRenderer(DynamicWidthRenderer())
	chart.getCategoryPlot().getRenderer().setBarPainter(StandardBarPainter())
	chart.getCategoryPlot().getRenderer().setShadowVisible(False)

```

**The preceding code produces the following result:**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/d/7d51cc1406f3407116f283b70328e7e3dea27e8b.png)

---

_[View the full topic](https://forum.inductiveautomation.com/t/change-each-bar-width-in-histogram-chart/66847)._
