如何设置饼图label并设置数值格式

来源:百度文库 编辑:神马文学网 时间:2024/07/03 09:35:02
关键字: jfreechart 饼图 标签 数值格式 百分比


/**

**QQ:252574345

**MSN:lele_love_lomboz@hotmail.com

*/

        PiePlot pieplot = (PiePlot)chart.getPlot();

        pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}"
                ,NumberFormat.getNumberInstance(),new DecimalFormat("0.00%")));

StandardPieSectionLabelGenerator参数说明:

 

 

//{0}{2}是组合显示效果,显示例如

水果

56.98%

这样的效果,说明该饼图块为水果,其占的比重为56.89%

 

//组合中的数值为0代表 图例中显示names[i]的值

//组合中的数值为1代表 图例中显示values[i]的值

//组合中的数值为2代表 图例中显示计算后自动得到的各个块的百分比

//new DecimalFormat("0.00%")  为显示格式设置.比如

new DecimalFormat("0.00")   则显示数值为56.89

new DecimalFormat("0")   则显示数值为57

new DecimalFormat("0%")   则显示数值为57%