首页 > 代码库 > Java 报表之JFreeChart(第一讲)
Java 报表之JFreeChart(第一讲)
1、利用 JFreeChart 创建垂直柱状报表
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="http://www.mamicode.com/DisplayChart?filename=" width="700" height="500" border="0"> 15 </body> 16 </html>
2、利用 JFreeChart 创建横向柱状报表
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="http://www.mamicode.com/DisplayChart?filename=" width="700" height="500" border="0"> 15 </body> 16 </html>
声明:此程序代码本人只是用于学习总结,非原创,如有侵权,联系本人。
Java 报表之JFreeChart(第一讲)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。