1package com.chart.demmo;
 2
 3import java.io.IOException;
 4
 5import javax.servlet.ServletRequest;
 6import javax.servlet.ServletResponse;
 7import javax.servlet.http.HttpServlet;
 8
 9import org.jfree.chart.ChartFactory;
10import org.jfree.chart.ChartUtilities;
11import org.jfree.chart.JFreeChart;
12import org.jfree.data.general.DefaultPieDataset;
13
14/**
15 * @author 韩曦
16 *          email: hanxi@tjhq.com
17 *          blog:   http://www.blogjava.net/hill
18 * @date Jan 12, 20094:19:33 PM
19 */

20public class ChartDemoServlet extends HttpServlet {
21    
22    public void service(ServletRequest request,ServletResponse response)
23    {
24        response.setContentType("image/jpeg");
25        DefaultPieDataset data=getDataSet();
26        
27        JFreeChart chart=ChartFactory.createPieChart3D("水果产量图", data, truefalsefalse);
28        try {
29            ChartUtilities.writeChartAsJPEG(response.getOutputStream(), chart, 300400);
30            System.out.print("OK");
31        }
 catch (IOException e) {
32            // TODO Auto-generated catch block
33            e.printStackTrace();
34        }

35    }

36
37    /**
38     * 获取一个演示用的简单数据集对象
39     * @return
40     */

41    private static DefaultPieDataset getDataSet() {
42        DefaultPieDataset dataset = new DefaultPieDataset();
43        dataset.setValue("苹果",100);
44        dataset.setValue("梨子",200);
45        dataset.setValue("葡萄",300);
46        dataset.setValue("香蕉",400);
47        dataset.setValue("荔枝",500);
48        return dataset;
49    }

50
51}

52


开心过好每一天。。。。。