Search code examples
javajasper-reportsjfreechart

How to show labels on top of bar with some space in jasper report?


I am working on a jasper report in which I am using java customizers to make some changes in the chart look. In my report I am creating a bar chart which looks like below:

enter image description here

Here I am using following code to show labels on top of bars:

CategoryPlot plot = (CategoryPlot)chart.getPlot();
BarRenderer barRenderer = (BarRenderer)plot.getRenderer();
CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
categoryPlot.getRenderer().setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));

I want to increase the space between top of bars and labels. I am not getting a way to do this. Can someone suggest me how to do this?


Solution

  • Try adding an offset to the label anchor:

    categoryPlot.getRenderer().setItemLabelAnchorOffset(10.0d);