環境:JDK1.4.2
JFreeChart: jfreechart-1.0.6
看見有的人Blog裏面要"餅圖顯示百分比"是用這個類
原來在1.0.0-rc1版中顯示百分比已經調整到StandardPieItemLabelGenerator構造函數中了,StandardPieItemLabelGenerator有三個構造函數。StandardPieItemLabelGenerator()不顯示各項所佔比例。另外兩個可以顯示比例。代碼如下:
//或者採用下面自定義樣式顯示,{0}表示選項,{1}表示數值,{2}表示所佔比例
plot.setLegendLabelGenerator(new StandardPieItemLabelGenerator("{0}: ({1}M, {2})"));
但是我用的是jfreechart-1.0.6這個版本,以上的StandardPieItemLabelGenerator,StandardPieItemLabelGenerator這2個類已經取消了換成了
StandardPieItemLabelGenerator------->>>>StandardPieToolTipGenerator (1.0.6版本)
我實現 “百分比”的方法如下:
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}=({1}M, {2})"));
具體的代碼 請看我下面的文章
JFreeChart+sql 生成餅圖