JFreeChart Chart Labels

I made it possible for value labels to appear on top of a line in JFreeChart. However, it would be better if the labels are inside the bars. How to do it? The following figure shows how I want the chart to look.

Bar Graph with Label inside bar

+4
source share
3 answers

I used the following code to make it work:

StackedBarRenderer renderer = new StackedBarRenderer(false); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); chart.getCategoryPlot().setRenderer(renderer);` 
+9
source

Just specify the desired ItemLabelPosition in the CategoryItemLabelGenerator . BarChartDemo3 is an example shown here .

+5
source

You can use ItemLabelPosition DOC Here

 renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,TextAnchor.TOP_CENTER )) 

Output: -

enter image description here

+4
source

All Articles