java JFreeChart 条形图标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7155294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 18:52:23  来源:igfitidea点击:

JFreeChart Bar Graph Labels

javajfreechart

提问by codix

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.

我使值标签可以出现在 JFreeChart 中的栏顶部。但是,如果标签位于条形内部,效果会更好。我如何使这项工作?下图显示了我希望图形的外观。

Bar Graph with Label inside bar

条形图中带有标签的条形图

回答by codix

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

回答by trashgod

Just specify the desired ItemLabelPositionin your CategoryItemLabelGenerator. BarChartDemo3is an example, shown here.

只需ItemLabelPosition在您的CategoryItemLabelGenerator. BarChartDemo3是一个例子,显示在这里

回答by JDGuide

You can use ItemLabelPositionDOC Here

您可以在此处使用ItemLabelPosition DOC

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

Output :-

输出 :-

enter image description here

在此处输入图片说明