Report bar chart label configuration

Hi,

You can increase the Y axis upper margin (% of range) property. This will give more space for the bar labels to be displayed correctly.

Regarding the label formatting, you can use the code from this post as a base.
Bar Chart (stacked) - How to hide labels if they equal zero

Below, I also modified the label font size.

from org.jfree.chart.labels import StandardCategoryItemLabelGenerator
from java.awt import Font
class myLabelGenerator(StandardCategoryItemLabelGenerator):
	def generateLabel(self,dataset,series, category):
		value = dataset.getValue(series,category)
		if value == 0:
			return None
		else:
			return str(int(value)) + " min"
	
	
plot = chart.getPlot()
renderer = plot.getRenderer()
renderer.setItemLabelGenerator(myLabelGenerator())
renderer.setItemLabelsVisible(True)
renderer.setBaseItemLabelFont(Font("Dialog", Font.PLAIN, 14))

Hope this helps,

1 Like