public class PieServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //创建数据源 //创建jreechart对象,用于绘制成图表 //生成图片,输出 // DefaultPieDataset dataset=new DefaultPieDataset(); // dataset.setValue("Category1", 48.5); // dataset.setValue("Category2", 21.5); // dataset.setValue("Category3", 30); // JFreeChart jfc=ChartFactory.createPieChart(new String("JFreeDemo", dataset); DefaultCategoryDataset dataset=new DefaultCategoryDataset();//创建折线图的数据源 dataset.addValue(100, "First", "2012"); dataset.addValue(3, "First", "2013"); dataset.addValue(10, "First", "2014"); dataset.addValue(120, "First", "2015"); dataset.addValue(50, "First", "2016"); dataset.addValue(200, "First", "2017"); dataset.addValue(20, "str", "2012"); dataset.addValue(34, "str", "2013"); dataset.addValue(50, "str", "2014"); dataset.addValue(16, "str", "2015"); dataset.addValue(530, "str", "2016"); dataset.addValue(200, "str", "2017"); JFreeChart jfc=ChartFactory.createLineChart("标题","x坐标说明", "y坐标说明", dataset,PlotOrientation.VERTICAL,true,true,false);//创建jreechart对象,用于绘制成图 表 response.setContentType("image/png"); OutputStream out=response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, jfc, 500, 300);//生成图片,输出 out.flush(); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } }
java的绘画图报表的组件_JFreeChart
时间: 2024-10-29 04:01:29