jfreechart的饼图默认显示数值,如何改为百分比?
如题
虽然我可以
plot.setLabelGenerator(new PieSectionLabelGenerator(){
public String generateSectionLabel(PieDataset dataset,
Comparable key) {
...
}
});
不过这样好像要自己计算百分比,比较麻烦,不知道还有没有更好的办法?
在网上找到一篇文章,不过比较旧,它用的方法和字段我都找不到,好像API已经变了,它的片断如下
...
PiePlot pie = (PiePlot)chart.getPlot();
//pie.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
pie.setSectionLabelType(PiePlot.NAME_AND_VALUE_LABELS);
//设定显示格式(名称加百分比或数值)
pie.setPercentFormatString("#,###0.0#%");
//设定百分比显示格式
...