简体   繁体   中英

How can I make a JFreeChart Bar Chart's plot expand to show vertical labels above the bars?

I want to create a Bar Chart, using JFreeChart, with vertical labels above the bars. I can do this using an ItemLabelPositioner as follows:

BarRenderer renderer = (BarRenderer)plot.getRenderer();
ItemLabelPosition pOut = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
renderer.setBasePositiveItemLabelPosition(pOut);

However, the labels on the tallest bars go off the top of the chart. Is there a way I can prevent this without doing complicated calculations on label sizes and setting the upper margin?

您可以使用如下所示的内容:

renderer.setItemLabelAnchorOffset(10); //giving some margins

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM