Change each bar width in histogram chart

@prasath.t - It certainly looks like this is possible. To get you started, below is an example of how to extend the BarRenderer class 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:

	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:

1 Like