Report bar chart label configuration

I’m making a report in ignition 7.9.2, y have to display a bar chart with the item label number in 45 degrees up… after some web digging i wrote a code in the scripting section in the chart confguration that can do it (i’m very very new with jfree code), but the numbers are not diplaying correctly when they’re more than 2 characters… how can i add some upper margin and format like ‘#.##0.0’ to the labels??
here is the code used to the label anlge and the result image

from org.jfree.chart.labels import ItemLabelPosition
from org.jfree.chart.labels import ItemLabelAnchor
from org.jfree.ui import TextAnchor
plot = chart.getPlot()
renderer = plot.getRenderer()
renderer.setBasePositiveItemLabelPosition(ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.BASELINE_LEFT, -45))	



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
			return str(int(value)) + " min"
plot = chart.getPlot()
renderer = plot.getRenderer()
renderer.setBaseItemLabelFont(Font("Dialog", Font.PLAIN, 14))

Hope this helps,

1 Like