饼图显示百分比

来源:互联网 发布:midi音乐软件 编辑:程序博客网 时间:2024/05/17 07:47

环境:JDK1.4.2

JFreeChart: jfreechart-1.0.6

看见有的人Blog里面要"饼图显示百分比"是用这个类

原来在1.0.0-rc1版中显示百分比已经调整到StandardPieItemLabelGenerator构造函数中了,StandardPieItemLabelGenerator有三个构造函数。StandardPieItemLabelGenerator()不显示各项所占比例。另外两个可以显示比例。代码如下:

plot.setLabelGenerator(new StandardPieItemLabelGenerator(StandardPieItemLabelGenerator.DEFAULT_TOOLTIP_FORMAT));
//或者采用下面自定义样式显示,{0}表示选项,{1}表示数值,{2}表示所占比例
plot.setLegendLabelGenerator(new StandardPieItemLabelGenerator("{0}: ({1}M, {2})"));

但是我用的是jfreechart-1.0.6这个版本,以上的StandardPieItemLabelGenerator,StandardPieItemLabelGenerator这2个类已经取消了换成了

 

StandardPieItemLabelGenerator------->>>>StandardPieSectionLabelGenerator    (1.0.6版本)

StandardPieItemLabelGenerator
------->>>>StandardPieToolTipGenerator     (1.0.6版本)

我实现 “百分比”的方法如下:

 

//设置百分比
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
plot.setLegendLabelGenerator(
new StandardPieSectionLabelGenerator("{0}=({1}M, {2})"));

具体的代码  请看我下面的文章 

JFreeChart+sql 生成饼图

原创粉丝点击