package cn.itcast.cc.servlet.cewolf; import java.io.IOException; import java.util.Date; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jfree.data.category.DefaultIntervalCategoryDataset; import de.laures.cewolf.DatasetProducer; public class CewolfServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 生成数据 DatasetProducer categoryData = new DatasetProducer() { public Object produceDataset(Map params) { final String[] categories = { "一季度", "二季度", "三季度", "四季度" }; final String[] seriesNames = { "研发部", "销售部", "教育部", "项目部" }; final Integer[][] startValues = new Integer[seriesNames.length][categories.length]; final Integer[][] endValues = new Integer[seriesNames.length][categories.length]; for (int series = 0; series < seriesNames.length; series++) { for (int i = 0; i < categories.length; i++) { int y = (int) (Math.random() * 10 + 1); startValues[series][i] = new Integer(y); endValues[series][i] = new Integer(y + (int) (Math.random() * 10)); } } DefaultIntervalCategoryDataset ds = new DefaultIntervalCategoryDataset( seriesNames, categories, startValues, endValues); return ds; } public String getProducerId() { return "CategoryDataProducer"; } public boolean hasExpired(Map params, Date since) { return false; } }; // 添加到Request中 request.setAttribute("categoryData", categoryData); // 转发到test.jsp页面 request.getRequestDispatcher("testcewolf.jsp").forward(request, response); } } |