private void createPieChart(String fileName) throws IOException
{
// 饼图数据源
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("中国", 44.4);
dataset.setValue("美国", 25.5);
dataset.setValue("日本", 18.5);
dataset.setValue("刚果", 4.6);
dataset.setValue("英国", 5.5);
dataset.setValue("其他", 0.5);
// 生成3D饼图
PiePlot3D plot = new PiePlot3D(dataset);
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
// 设置图片链接
plot.setURLGenerator(new StandardPieURLGenerator(
"http://wenkaixuan.iteye.com"));
JFreeChart chart = new JFreeChart("人口统计表",
JFreeChart.DEFAULT_TITLE_FONT, plot, true);
//设置背景色
chart.setBackgroundPaint(Color.WHITE);
//path代表当前服务器上下文路径
String path = ServletActionContext.getRequest().getSession().getServletContext().getRealPath("/");
//保存图片
ChartUtilities.saveChartAsJPEG(new File(path + "img/" + fileName + ".jpg"), chart, 1024, 768);
}