餅圖顯示百分比

環境: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 生成餅圖

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章