我正在尝试创建堆积条形图。我的要求是我需要栏内的百分比组成和栏顶部的总数。请提出解决方案。
我的要求:示例:http ://www.jfree.org/jfreechart/api/javadoc/images/StackedBarRenderer3DSample.png
我想要栏内的百分比成分和栏顶部的总成分。
我正在尝试创建堆积条形图。我的要求是我需要栏内的百分比组成和栏顶部的总数。请提出解决方案。
我的要求:示例:http ://www.jfree.org/jfreechart/api/javadoc/images/StackedBarRenderer3DSample.png
我想要栏内的百分比成分和栏顶部的总成分。
I ran into the same problem too. For some reason the latest version of JFreeChart does not display the percentage composition inside the bar. Here's how I got it to work:
StackedBarRenderer br = new StackedBarRenderer(true); //enable perc. display
br.setBarPainter(new StandardBarPainter());
br.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
br.setBaseItemLabelsVisible(true);
chart.getCategoryPlot().setRenderer(br);
Hope this helps
It's not clear what you are doing now, but using a StackedBarRenderer
with setRenderAsPercentages(true)
will display the percentages. To get the total, extend StackedBarRenderer
, loop through the dataset for each column, and override drawItem()
to draw the result. An example may be found in the JFreeChart Demo as part of StackedBarChartDemo3
.
As an alternative, consider a custom CategoryToolTipGenerator
, added via setBaseToolTipGenerator()
.
Addendum: You linked to an example using StackedBarRenderer3D
, which also has a setRenderAsPercentages()
method. It can be extended similarly.