JFreeChart的简单应用以及解决中文显示方框的问题(二)

2014-11-24 10:08:58 · 作者: · 浏览: 4
Font("黑体", Font.BOLD, 20);
TextTitle textTitle = chart.getTitle();
textTitle.setFont(titleFont);// 为标题设置上字体

Font plotFont = new Font("宋体", Font.PLAIN, 16);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelFont(plotFont); // 为饼图元素设置上字体

Font LegendFont = new Font("楷体", Font.PLAIN, 18);
LegendTitle legend = chart.getLegend(0);
legend.setItemFont(LegendFont);// 为图例说明设置字体
这是中文显示效果如下:

此时显示了中文,另外可能你需要显示每一种情况占用的百分比是多少,这时候可以添加这样的代码:
[java]
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {2}",NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));// 显示百分比
此时显示的效果如下:

注意以上添加的代码需要在输出图表之前加上,否则看不到效果的。