我是看到这个链接做的
http://hi.baidu.com/python811022/item/3f01cc25194c0d102b0f1c38
下面是我写的servlet
package com.xiaolu.web.servlet; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jfree.chart.ChartRenderingInfo; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.entity.StandardEntityCollection; import org.jfree.chart.labels.StandardPieToolTipGenerator; import org.jfree.chart.plot.PiePlot3D; import org.jfree.data.general.DefaultPieDataset; public class JfreeChartDemo extends HttpServlet{ /** * */ private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //数据源 DefaultPieDataset data = new DefaultPieDataset(); data.setValue("高中以下",370); data.setValue("高中",1530); data.setValue("大专",5700); data.setValue("本科",8280); data.setValue("硕士",4420); data.setValue("博士",80); //3D饼图 PiePlot3D plot = new PiePlot3D(data); plot.setToolTipGenerator(new StandardPieToolTipGenerator()); JFreeChart chart = new JFreeChart("程序员学历情况调查表", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(java.awt.Color.white);//可选,设置图片背景色 StandardEntityCollection sec = new StandardEntityCollection(); ChartRenderingInfo info = new ChartRenderingInfo(sec); String path = this.getServletContext().getRealPath("/image"); String file = path+"\\chart1.jpg"; ChartUtilities.saveChartAsJPEG(new File(file), chart, 500, 300,info); request.setAttribute("url", file); request.getRequestDispatcher("/index.jsp").forward(request, response); } }