使用jfree在jsp中创建饼图时出错

时间:2012-08-16 07:26:27

标签: java jsp servlets pie-chart

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.BasicStroke;
import java.awt.Color;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.data.jdbc.JDBCPieDataset;
import java.io.OutputStream;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.Connection;

public class Chart1 extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public Chart1() {
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Connection connection = null;
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            try {
                connection =
                        DriverManager.getConnection("jdbc:mysql://localhost/security?user=root&password=root&useUnicode=true&characterEncoding=utf-8");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        JDBCPieDataset dataset = new JDBCPieDataset(connection);
        try {
            dataset.executeQuery("Select country,revenue From country_revenue order by revenue desc");
             * * * * * JFreeChart chart = ChartFactory.createPieChart("Country - Revenue Chart", dataset, true, true, false);
             * * * *
                    * chart.setBorderPaint(Color.black);
            chart.setBorderStroke(new BasicStroke(10.0f));
            chart.setBorderVisible(true);
            if (chart != null) {
                int width = 500;
                int height = 350;
                final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
                response.setContentType("image/png");
                OutputStream out = response.getOutputStream();
                ChartUtilities.writeChartAsPNG(out, chart, width, height, info);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }
}

它给了我这个错误: ChartFactory类型中的方法createPieChart(String,PieDataset,boolean,boolean,boolean)不适用于参数(String,JDBCPieDataset,boolean,boolean,boolean)

我该如何解决?

0 个答案:

没有答案