Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JFreeChart Bar Graph Labels

I have made it possible for value labels to appear on top of the bar in JFreeChart. However, it would look better if the labels are inside the bars. How do I make this work? The image below shows what I wanted the graph to look like.

Bar Graph with Label inside bar

like image 394
codix Avatar asked Dec 02 '22 02:12

codix


2 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);`
like image 82
codix Avatar answered Dec 09 '22 13:12

codix


You can use ItemLabelPosition DOC Here

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

Output :-

enter image description here

like image 27
JDGuide Avatar answered Dec 09 '22 12:12

JDGuide