JFreeChart 饼图显示百分比

JFreeChart chart = ChartFactory.createPieChart3D(title, // 图表标题 
dataset, true, // 是否显示图例 
false, false); 
PiePlot pieplot = (PiePlot) chart.getPlot(); //通过JFreeChart 对象获得 
pieplot.setNoDataMessage("无数据可供显示!"); // 没有数据的时候显示的内容 
pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator( 
("{0}: ({2})"), NumberFormat.getNumberInstance(), 
new DecimalFormat("0.00%"))); 


    其中new StandardPieSectionLabelGenerator( 
("{0}: ({1},{2})"), NumberFormat.getNumberInstance(), 
new DecimalFormat("0.00%")) 
    的("{0}: ({1},{2})")是生成的格式,{0}表示section名,{1}表示section的值,{2}表示百分比。可以自定义。而new DecimalFormat("0.00%")表示小数点后保留两位 

posted on 2013-07-13 14:23  CaptainLuffy  阅读(1195)  评论(0编辑  收藏  举报