How to hide labels which are zero in Bar charts

Hi,
I am using a Stacked bar chart to show the Downtime in Hours for all days in a month, I would like to hide the labels which are zero in the chart.
Is it possible to hide the labels which are only 0 in the bar chart?
Did we need to do use configure chart in the Component scripting section to achieve the same?
Any help will be appreciated!

If the data is coming from a binding then you just need to add a script transform to the binding to weed out the bits you don’t want. The database results will be returned as value and you just add some transform code like this:

# This code assumes that value format is like 
# [{"date": '2022-03-01', "hours": 0.6}, {"date": '2022-03-02", "hours": 0}, ...]
output = []
for row in value:
    if  row['hours'] > 0:
        output.append({"date": value['date'], "hours": value['hours']})
return output
1 Like

Just a guess, since they didn’t actually say and there is no tag, but since the OP mentions the Component scripting section, I believe they are referencing Vision, in which case a transform is not available.

@Vengatesan_S If this is for vision, you can create a custom Label Generator in the configureChart function. Something like this:

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

chart = event.source.parent.getComponent(‘Bar Chart’).getChart()
plot = chart.getPlot()
renderer = plot.getRenderer()
renderer.setItemLabelGenerator(myLabelGenerator())
renderer.setItemLabelsVisible(True)
2 Likes

Thanks @Transistor and Irose, As i am using Vision Irose’s solution worked out for me , I just used that script in property change.

Please remember to use the appropriate tag when writing a question!

Thanks Irose for the solution. Is it possible to position the bar label at center with this solution?

Adjustments to label position are certainly doable, but can you elaborate or perhaps provide a sample picture of what you mean by this?

1 Like