JFreeChart Bar Graph Labels

百般思念 提交于 2020-01-11 05:57:29

问题


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.


回答1:


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);`



回答2:


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




回答3:


You can use ItemLabelPosition DOC Here

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

Output :-



来源:https://stackoverflow.com/questions/7155294/jfreechart-bar-graph-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!