# Bar Chart (stacked) - How to hide labels if they equal zero

**URL:** <https://forum.inductiveautomation.com/t/bar-chart-stacked-how-to-hide-labels-if-they-equal-zero/12299>\
**Category:** Ignition\
**Created:** [October 27, 2016, 8:26pm UTC](https://forum.inductiveautomation.com/t/bar-chart-stacked-how-to-hide-labels-if-they-equal-zero/12299 "2016-10-27T20:26:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrandonSHill](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandonshill/32/6805_2.png) [@BrandonSHill](https://forum.inductiveautomation.com/u/BrandonSHill)\
**Post date:** [October 27, 2016, 8:26pm UTC](https://forum.inductiveautomation.com/t/bar-chart-stacked-how-to-hide-labels-if-they-equal-zero/12299/1 "2016-10-27T20:26:16Z")

</div>

Title pretty much says it. I have a bar chart that has several stacked bars and “they” want the labels to show, however, several of those bars have a value of 0 (zero). Anyone happen to know a way to hide a value of zero on a label on the Bar Chart? I have a feeling this will end up being an import of jfree libraries to access the chart from that side, but unsure how to go about it.

Any help would be great.

Thanks!

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [October 28, 2016, 2:50pm UTC](https://forum.inductiveautomation.com/t/bar-chart-stacked-how-to-hide-labels-if-they-equal-zero/12299/2 "2016-10-28T14:50:15Z")

</div>

[code]from org.jfree.chart.labels import StandardCategoryItemLabelGenerator

class myLabelGenerator(StandardCategoryItemLabelGenerator):  
def generateLabel(self,dataset,series, category):   
value = dataset.getValue(series,category)   
if value == 0:  
return None  
else:  
return str(int(value))

chart = event.source.parent.getComponent(‘Bar Chart’).getChart()  
plot = chart.getPlot()  
renderer = plot.getRenderer()  
renderer.setItemLabelGenerator(myLabelGenerator())  
renderer.setItemLabelsVisible(True)[/code]

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [September 5, 2018, 4:02pm UTC](https://forum.inductiveautomation.com/t/bar-chart-stacked-how-to-hide-labels-if-they-equal-zero/12299/3 "2018-09-05T16:02:50Z")

</div>

Hi @jpark  
What if I want to use `StandardCategoryItemLabelGenerator(String labelFormat, NumberFormat formatter)` instead of just the default `StandardCategoryItemLabelGenerator()` that only takes in on argument, how would that work here? I want to change the format of the text and I somehow could not figure it out to save my life… 😢

I want to use {“2”} as the label format and either “#,#0.00” or “0” for the number format depending on a if else statement.

if I use `StandardCategoryItemLabelGenerator("{2}", DecimalFormat("XXX"))` it works like a charm but I cant get it to work when I try to pass the different Number formating.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 5, 2018, 4:20pm UTC](https://forum.inductiveautomation.com/t/bar-chart-stacked-how-to-hide-labels-if-they-equal-zero/12299/4 "2018-09-05T16:20:25Z")

</div>

You should be able to modify the subclass to use an explicit constructor (Jython’s ` __init__ ` auto-magically wraps Java constructors, even overloaded ones):

```auto
class myLabelGenerator(StandardCategoryItemLabelGenerator):
	def __init__ (self, labelFormat, formatter):
		super(). __init__ (labelFormat, formatter)
		
	def generateLabel(self,dataset,series, category):	
		value = dataset.getValue(series,category)	
		if value == 0:
			return None
		else:
			return str(int(value))

```

Then use it with your label/formatter as expected:  
`renderer.setItemLabelGenerator(myLabelGenerator('{"2"}', myNumberFormatter))`
