标签:
1 package com.wcy.chart.bar; 2 3 import javax.servlet.http.HttpSession; 4 5 import org.jfree.chart.ChartFactory; 6 import org.jfree.chart.JFreeChart; 7 import org.jfree.chart.plot.PlotOrientation; 8 import org.jfree.chart.servlet.ServletUtilities; 9 import org.jfree.data.category.DefaultCategoryDataset; 10 11 public class BarChart1 { 12 13 public static String genBarChart(HttpSession session) throws Exception { 14 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 15 dataset.addValue(510, "深圳", "苹果"); 16 dataset.addValue(320, "深圳", "香蕉"); 17 dataset.addValue(580, "深圳", "橘子"); 18 dataset.addValue(390, "深圳", "梨子"); 19 JFreeChart chart=ChartFactory.createBarChart3D("水果销售统计图", "水果", "销售", dataset, 20 PlotOrientation.VERTICAL, true, true, true); 21 String fileName=ServletUtilities.saveChartAsPNG(chart, 700, 500, null,session); 22 return fileName; 23 } 24 }
1 <%@page import="com.wcy.chart.bar.BarChart1"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3 pageEncoding="UTF-8"%> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head> 10 <body> 11 <% 12 String fileName = BarChart1.genBarChart(session); 13 %> 14 <img src="DisplayChart?filename=<%=fileName %>" width="700" height="500" border="0"> 15 </body> 16 </html>
1 package com.wcy.chart.bar; 2 3 import javax.servlet.http.HttpSession; 4 5 import org.jfree.chart.ChartFactory; 6 import org.jfree.chart.JFreeChart; 7 import org.jfree.chart.plot.PlotOrientation; 8 import org.jfree.chart.servlet.ServletUtilities; 9 import org.jfree.data.category.DefaultCategoryDataset; 10 11 public class BarChart2 { 12 13 public static String genBarChart(HttpSession session)throws Exception{ 14 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 15 dataset.addValue(510, "深圳", "苹果"); 16 dataset.addValue(320, "深圳", "香蕉"); 17 dataset.addValue(580, "深圳", "橘子"); 18 dataset.addValue(390, "深圳", "梨子"); 19 JFreeChart chart = ChartFactory.createBarChart3D("水果销量统计图", "水果", "销售", dataset, PlotOrientation.HORIZONTAL, true,true, true); 20 String fileName = ServletUtilities.saveChartAsPNG(chart, 700, 500, null, session); 21 return fileName; 22 } 23 }
1 <%@page import="com.wcy.chart.bar.BarChart2"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3 pageEncoding="UTF-8"%> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head> 10 <body> 11 <% 12 String fileName = BarChart2.genBarChart(session); 13 %> 14 <img src="DisplayChart?filename=<%=fileName %>" width="700" height="500" border="0"> 15 </body> 16 </html>
声明:此程序代码本人只是用于学习总结,非原创,如有侵权,联系本人。
标签:
原文地址:http://www.cnblogs.com/wangchaoyuan/p/5972807.html