- 浏览: 66030 次
- 性别:
- 来自: 黑龙江
文章分类
最新评论
-
Ethan楚翔:
jdk1.7运行报错,大家用1.6以下版本
Spring AOP 简单demo -
springaop_springmvc:
apache lucene开源框架demo使用实例教程源代码下 ...
Lucene与DB结合示例 -
fl_zxf:
在看,3Q
Lucene与DB结合示例 -
jushi1988:
哎.米休 写道在action的第一行会报空指针异常 求解啊你看 ...
Lucene与DB结合示例 -
哎.米休:
在action的第一行会报空指针异常 求解啊
Lucene与DB结合示例
很久以前看了点jfreechart相关的东西,就做了一个小例子。项目就是一个简单的web工程,名字叫JFreeChartTest。
数据库是Mysql,还是基本的JDBC。
1、工具包 代码如下:
(1) Configuration 类
package com.jushi.utils; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class Configuration { private Properties properties; private final static Configuration cfg = new Configuration(); private Configuration() { properties = new Properties(); InputStream is = null; try { is = getClass().getResourceAsStream("/gdb.properties"); properties.load(is); } catch (Exception e) { System.out.println("不能加载gdb.properties文件....."); e.printStackTrace(); } finally { try { if (is != null) is.close(); } catch (IOException io) { io.printStackTrace(); } } } public static Configuration getInstance() { return cfg; } public String getValue(String key) { return properties.getProperty(key); } }
(2) DBConnManager 类 数据连接管理类
package com.jushi.utils; import java.io.Serializable; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Vector; public class DBConnManager implements Serializable { private final static DBConnManager instance = new DBConnManager(); private DBConnManagerPool pool; /** * 获得DBConnManager的实例 */ public static DBConnManager getInstance() { return instance; } /** * 获取连接 * * @return * @throws SQLException */ public Connection getConnection() throws SQLException { return pool.getConnection(); } /** * 释放连接 * * @param con * @throws SQLException */ public void freeConnection(Connection con) throws SQLException { pool.freeConnection(con); } /** * 初始化构造函数 */ private DBConnManager() { init(); } /** * 初始化 */ private void init() { Configuration cfg = Configuration.getInstance(); String db_driver = cfg.getValue("DB.DRIVER"); String db_url = cfg.getValue("DB.URL"); String db_user = cfg.getValue("DB.USER"); String db_password = cfg.getValue("DB.PASSWORD"); int db_maxconn = Integer.parseInt(cfg.getValue("DB.MAX_CONNECTIONS")); try { Class.forName(db_driver); } catch (Exception e) { e.printStackTrace(); } pool = new DBConnManagerPool(db_url, db_user, db_password, db_maxconn); } /** * 内部类 */ class DBConnManagerPool { private Vector freeConns = new Vector(); private int maxConn; private int connNum; private String URL; private String user; private String password; public DBConnManagerPool(String URL, String user, String password, int maxConn) { this.URL = URL; this.user = user; this.password = password; this.maxConn = maxConn; } public synchronized void freeConnection(Connection conn) { freeConns.add(conn); connNum--; notifyAll(); } public synchronized Connection getConnection() throws SQLException { Connection conn = null; if (freeConns.size() > 0) { conn = (Connection) freeConns.firstElement(); freeConns.removeElementAt(0); try { if (conn.isClosed()) { conn = getConnection(); } } catch (Exception e) { conn = getConnection(); } } else if (maxConn == 0 || connNum < maxConn) { conn = newConnection(); } if (conn != null) { connNum++; } return conn; } /** * 通过url,user,password 加载数据库驱动,连接数据库 * * @return * @throws SQLException */ private Connection newConnection() throws SQLException { Connection con = DriverManager.getConnection(URL, user, password); return con; } } public static void main(String as[]) throws Exception { Connection conn = instance.getConnection(); System.out.println("=============" + conn); } }
2、业务逻辑加dao 因为只是测试 就混在一起了
DomainService 类
package com.jushi.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import com.jushi.utils.DBConnManager; /** * 主要生成立体直方图、柱形图、饼图、曲线图的service混合dao * * @author jushi * */ public class DomainService { private static DomainService instance; private Connection conn; private PreparedStatement ps; private ResultSet rs; public static DomainService getInstance() { if (instance == null) { instance = new DomainService(); } return instance; } private DomainService() { } public String getAllProductsTotal() { StringBuffer product = new StringBuffer(); String str1 = "", str2 = ""; try { String sql = "select count(id) as total,productname,type from product group by productname,type order by productname"; conn = DBConnManager.getInstance().getConnection(); ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { String productname = rs.getString("productname"); String type = rs.getString("type"); String total = rs.getString("total"); if (type.equals("20-25")) { str1 += type + "," + productname + "," + total + "!"; } else str2 += type + "," + productname + "," + total + "!"; } product.append(str1 + "@" + str2); } catch (Exception e) { e.printStackTrace(); } finally { try { DBConnManager.getInstance().freeConnection(conn); } catch (Exception e) { e.printStackTrace(); } } return product.toString(); } public int getAllCount() { int count = 0; try { String sql = "select count(id) as count from product"; conn = DBConnManager.getInstance().getConnection(); ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { count = rs.getInt(1); } return count; } catch (Exception e) { e.printStackTrace(); return 1; } finally { try { DBConnManager.getInstance().freeConnection(conn); } catch (Exception e) { e.printStackTrace(); } } } public static void main(String as[]) { DomainService.getInstance().getAllProductsTotal(); DomainService.getInstance().getAllCount(); } }
3. 生成图的类包
(1). 柱形图
package com.jushi.jfreechart; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GradientPaint; import javax.servlet.http.HttpSession; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; import org.jfree.chart.servlet.ServletUtilities; public class BarChartDemo extends ApplicationFrame { public BarChartDemo(String title) { super(title); CategoryDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartPanel panel = new ChartPanel(chart, false); panel.setPreferredSize(new Dimension(500, 300)); setContentPane(panel); } public static String getChart(HttpSession session, String title) { String fn = ""; new BarChartDemo(title); CategoryDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); try { fn = ServletUtilities.saveChartAsJPEG(chart, 600, 400, session); } catch (Exception e) { e.printStackTrace(); } return fn; } private static CategoryDataset createDataset() { //row String row1 = "2007年"; String row2 = "2008年"; String row3 = "2009年"; //column String col1 = "第一季度"; String col2 = "第二季度"; String col3 = "第三季度"; String col4 = "第四季度"; DefaultCategoryDataset defaultDataset = new DefaultCategoryDataset(); defaultDataset.addValue(1.0, row1, col1); defaultDataset.addValue(4.0, row1, col2); defaultDataset.addValue(6.0, row1, col3); defaultDataset.addValue(3.0, row1, col4); defaultDataset.addValue(2.0, row2, col1); defaultDataset.addValue(1.0, row2, col2); defaultDataset.addValue(3.0, row2, col3); defaultDataset.addValue(5.0, row2, col4); defaultDataset.addValue(3.0, row3, col1); defaultDataset.addValue(4.0, row3, col2); defaultDataset.addValue(6.0, row3, col3); defaultDataset.addValue(1.0, row3, col4); return defaultDataset; } private static JFreeChart createChart(CategoryDataset data) { JFreeChart chart = ChartFactory.createBarChart("2007-2009年年度营业额柱状图", "营业额柱状图", "百万(RMB)", data, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); GradientPaint paint = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint paint1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint paint2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer .setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("黑体", Font.BOLD, 12));//12号黑体加粗 renderer.setItemLabelPaint(Color.black);//字体为黑色 renderer.setItemLabelsVisible(true); renderer.setSeriesPaint(0, paint); renderer.setSeriesPaint(1, paint1); renderer.setSeriesPaint(2, paint2); org.jfree.chart.axis.ValueAxis value = plot.getRangeAxis(); value.setUpperMargin(0.15);//设置最高的一个柱与图片顶端的距离(最高柱的15%) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions .createUpRotationLabelPositions(Math.PI / 6.0)); return chart; } public static void main(String as[]) { BarChartDemo bcd = new BarChartDemo("2007-2009年年度营业额柱状图"); bcd.pack(); RefineryUtilities.centerFrameOnScreen(bcd); bcd.setVisible(true); } }
(2). 3D柱形图
package com.jushi.jfreechart; import java.awt.Color; import java.awt.Font; import javax.servlet.http.HttpSession; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.servlet.ServletUtilities; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import com.jushi.dao.DomainService; public class Chart { public Chart() { super(); } public static String getChart(HttpSession session, String type) throws Exception { CategoryDataset dataset = getDataSet(type); JFreeChart chart = ChartFactory.createBarChart3D("产品购买年龄段统计图(日)", // 图表标题 "购买年龄段对比", // 目录轴的显示标签 "人数", // 数值轴的显示标签 dataset, // 数据集 PlotOrientation.VERTICAL, // 图表方向:水平、垂直 true, // 是否显示图例(对于简单的柱状图必须是false) true, // 是否生成工具 true // 是否生成URL链接 ); CategoryPlot plot = chart.getCategoryPlot();// 获得图表区域对象 // 设置图表的纵轴和横轴org.jfree.chart.axis.CategoryAxis org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.1);// 设置距离图片左端距离此时为10% domainAxis.setUpperMargin(0.1);// 设置距离图片右端距离此时为百分之10 domainAxis.setCategoryLabelPositionOffset(10);// 图表横轴与标签的距离(10像素) domainAxis.setCategoryMargin(0.2);// 横轴标签之间的距离20% // 设定柱子的属性 org.jfree.chart.axis.ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.1);// 设置最高的一个柱与图片顶端的距离(最高柱的10%) // 设置图表的颜色 org.jfree.chart.renderer.category.BarRenderer3D renderer; renderer = new org.jfree.chart.renderer.category.BarRenderer3D(); renderer.setBaseOutlinePaint(Color.red); renderer.setSeriesPaint(0, Color.cyan);// 计划柱子的颜色为青色 renderer.setSeriesOutlinePaint(0, Color.BLACK);// 边框为黑色 renderer.setSeriesPaint(1, Color.yellow);// 实报柱子的颜色为绿色 renderer.setSeriesOutlinePaint(1, Color.red);// 边框为红色 renderer.setItemMargin(0.1);// 组内柱子间隔为组宽的10% // 显示每个柱的数值,并修改该数值的字体属性 renderer .setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelFont(new Font("黑体", Font.BOLD, 12));// 12号黑体加粗 renderer.setItemLabelPaint(Color.black);// 字体为黑色 renderer.setItemLabelsVisible(true); plot.setRenderer(renderer);// 使用我们设计的效果 // 设置纵横坐标的显示位置 plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);// 学校显示在下端(柱子竖直)或左侧(柱子水平) plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // 人数显示在下端(柱子水平)或左侧(柱子竖直) String fn = ServletUtilities.saveChartAsJPEG(chart, 600, 450, null, session); return fn; } /** * 获取一个演示用的组合数据集对象 3D柱形图 * * @return */ private static CategoryDataset getDataSet(String type) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); String[] allpro = DomainService.getInstance().getAllProductsTotal() .split("@"); for (int i = 0; i < allpro.length; i++) { String[] single = allpro[i].split("!"); for (int j = 0; j < single.length; j++) { String[] single1 = single[j].split(","); for (int m = 0; m < single1.length; m++) { switch (Integer.parseInt(type)) { case 1: dataset.addValue(Double.parseDouble(single1[2]), single1[0], single1[1] + "岁"); break; case 2: dataset.addValue(Double.parseDouble(single1[2]), single1[1], single1[0] + "岁"); break; } } } } return dataset; } }
(3).折线图
package com.jushi.jfreechart; import java.awt.Color; import javax.servlet.http.HttpSession; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.servlet.ServletUtilities; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; import com.jushi.dao.DomainService; /** * 折线图 * * @author jushi * */ public class LineChart extends ApplicationFrame { public LineChart(String s, String type) { super(s); setContentPane(createDemoPanel(type)); } // 生成显示图表的面板 public static JPanel createDemoPanel(String type) { JFreeChart jfreechart = createChart(type); return new ChartPanel(jfreechart); } // 生成饼图数据集对象 public static DefaultCategoryDataset createDataset(String type) { DefaultCategoryDataset linedata = new DefaultCategoryDataset(); String[] allpro = DomainService.getInstance().getAllProductsTotal() .split("@"); for (int i = 0; i < allpro.length; i++) { String[] single = allpro[i].split("!"); for (int j = 0; j < single.length; j++) { String[] single1 = single[j].split(","); for (int m = 0; m < single1.length; m++) { switch (Integer.parseInt(type)) { case 1: linedata.addValue(Double.parseDouble(single1[2]), single1[0], single1[1] + "岁"); break; case 2: linedata.addValue(Double.parseDouble(single1[2]), single1[1], single1[0] + "岁"); break; } } } } return linedata; } /** * 返回jfreechart 对象 * * @param type * @return JFreeChart */ public static JFreeChart createChart(String type) { DefaultCategoryDataset linedata = createDataset(type); JFreeChart chart = ChartFactory.createLineChart("产品购买年龄段统计图(日)", "产品购买年龄段统计图(日)", "人数", linedata, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();// Y轴对象 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setUpperMargin(0.20); rangeAxis.setLowerMargin(0.2D); rangeAxis.setLabelAngle(Math.PI / 3.0); return chart; } /** * 生成折线图的文件 * * @return String * @param sesson * @param title */ public static String getLineChart(HttpSession session, String type) throws Exception { String file = ""; new PieChart("产品购买年龄段统计图(日)", type); JFreeChart piechart = createChart(type); try { file = ServletUtilities.saveChartAsJPEG(piechart, 600, 400, null, session); } catch (Exception e) { e.printStackTrace(); } return file; } public static void main(String as[]) { LineChart lc = new LineChart("折线图", "1"); lc.pack(); RefineryUtilities.centerFrameOnScreen(lc); lc.setVisible(true); } }
(4).饼图
package com.jushi.jfreechart; import java.awt.Font; import java.text.DecimalFormat; import java.text.NumberFormat; import java.awt.Color; import javax.servlet.http.HttpSession; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.block.BlockContainer; import org.jfree.chart.block.BorderArrangement; import org.jfree.chart.block.LabelBlock; import org.jfree.chart.labels.StandardPieSectionLabelGenerator; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.servlet.ServletUtilities; import org.jfree.chart.title.LegendTitle; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.HorizontalAlignment; import org.jfree.ui.RectangleEdge; import org.jfree.ui.RefineryUtilities; import com.jushi.dao.DomainService; public class PieChart extends ApplicationFrame{ public PieChart(String s,String type){ super(s); setContentPane(createDemoPanel(type)); } // 生成显示图表的面板 public static JPanel createDemoPanel(String type){ JFreeChart jfreechart = createChart(type); return new ChartPanel(jfreechart); } // 生成饼图数据集对象 public static PieDataset createDataset(String type){ DefaultPieDataset piedata = new DefaultPieDataset(); int count = DomainService.getInstance().getAllCount(); String[] allpro = DomainService.getInstance().getAllProductsTotal().split("@"); for(int i=0; i<allpro.length; i++){ String[] single = allpro[i].split("!"); for(int j=0; j<single.length; j++){ String[] single1= single[j].split(","); for(int m=0; m<single1.length; m++){ double dd = Double.parseDouble(single1[2])/Double.parseDouble(String.valueOf(count)); java.text.DecimalFormat df = new java.text.DecimalFormat("0.00"); String aa = df.format(dd); switch(Integer.parseInt(type)){ case 1: piedata.setValue(single1[1], Double.parseDouble(aa));break; case 2: piedata.setValue(single1[0], Double.parseDouble(aa));break; } } } } return piedata; } /** * 生成图表主对象JFreeChart * @param session * @return JFreeChart */ public static JFreeChart createChart(String type){ PieDataset piedata = createDataset(type); //定义图表对象 JFreeChart chart = ChartFactory.createPieChart("产品购买年龄段统计图(日)",piedata,true,true,false); //获得图表显示对象 PiePlot pieplot = (PiePlot) chart.getPlot(); //设置图表标签字体 pieplot.setLabelFont(new Font("宋体",Font.BOLD,12)); pieplot.setNoDataMessage("没有查询到数据"); pieplot.setCircular(true); pieplot.setLabelGap(0.01D);//间距 pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator( ("{0}: ({2})"), NumberFormat.getNumberInstance(), new DecimalFormat("0.00%"))); LegendTitle legendtitle = new LegendTitle(chart.getPlot()); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); LabelBlock labelblock = new LabelBlock("产品购买年龄段统计图(日)", new Font("宋体", 1, 13)); labelblock.setPadding(5D, 5D, 5D, 5D); blockcontainer.add(labelblock, RectangleEdge.TOP); LabelBlock labelblock1 = new LabelBlock(""); labelblock1.setPadding(8D, 20D, 2D, 5D); blockcontainer.add(labelblock1, RectangleEdge.BOTTOM); BlockContainer blockcontainer1 = legendtitle.getItemContainer(); blockcontainer1.setPadding(2D, 10D, 5D, 2D); blockcontainer.add(blockcontainer1); legendtitle.setWrapper(blockcontainer); legendtitle.setPosition(RectangleEdge.RIGHT); legendtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); legendtitle.setBackgroundPaint(Color.LIGHT_GRAY); chart.addSubtitle(legendtitle); return chart; } /** * 生成饼图的文件 * @return String * @param sesson * @param title */ public static String getPieChart(HttpSession session,String type) throws Exception{ String file =""; new PieChart("产品购买年龄段统计图(日)",type); JFreeChart piechart = createChart(type); try{ file = ServletUtilities.saveChartAsJPEG(piechart, 600, 400, null, session); }catch(Exception e){ e.printStackTrace(); } return file; } public static void main(String[] args){ PieChart pc = new PieChart("产品购买年龄段统计图(日)","1"); pc.pack(); RefineryUtilities.centerFrameOnScreen(pc); pc.setVisible(true); } }
4. gdb.properties 文件
#---Database--- DB.DRIVER=com.mysql.jdbc.Driver DB.URL=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gbk DB.USER=root DB.PASSWORD=jushi DB.MAX_CONNECTIONS=200
5. web.xml 文件内容 需要配置jfreechart的servlet
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>DisplayChart</servlet-name> <servlet-class> org.jfree.chart.servlet.DisplayChart </servlet-class> </servlet> <servlet-mapping> <servlet-name>DisplayChart</servlet-name> <url-pattern>/DisplayChart</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
6. 视图 index.jsp
<%@ page language="java" import="java.util.*,com.jushi.jfreechart.*" pageEncoding="GBK"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>chart</title> </head> <body> <center><font color=green size="10">立体直方图、饼图、柱形图、折线图 测试</font></center><hr> <center><a href="index.jsp?type=1">第一种</a> <a href="index.jsp?type=2">第二种</a></center> <hr/> <% String type = request.getParameter("type")==null?"1":request.getParameter("type"); String fn=Chart.getChart(request.getSession(),type);//立体直方图 String fn1 = BarChartDemo.getChart(request.getSession(),"2007-2009年年度营业额柱状图");//柱形图 String fn2 =PieChart.getPieChart(request.getSession(),type);//饼图 String fn3 = LineChart.getLineChart(request.getSession(),type);//曲线图 String path1 = basePath+"DisplayChart?filename="+fn1; String pathnew= basePath+"DisplayChart?filename="+fn; String path2 = basePath+"DisplayChart?filename="+fn2; String path3= basePath+"DisplayChart?filename="+fn3; %> <center><img src="<%=pathnew%>" border="0"/></center><hr> <center><img src="<%=path2 %>" border="0"/></center><hr> <center><img src="<%=path3 %>" border="0"/></center><hr> <center><img src="<%=path1 %>" border="0"/></center><hr> <br/> </body> </html>
运行 http://localhost:8080/JFreeChartTest/
附源码及数据库sql。
发表评论
-
HttpClient浅尝-小试牛刀
2011-06-13 17:07 1521今天,突然想重新研究下HttpClient的应用, ... -
Java查找指定文件的简单应用
2011-04-08 09:24 2040前段时间,应项目中需要,弄了一个关于删除某个时间段的临时文件、 ... -
基于WebService的应用
2010-03-22 16:44 2313前段日子看到了一个提供WEB服务的网站-www.web ... -
js 防止页面刷新
2010-03-18 11:02 12945var oLastBtn=0,bIsMenu=false i ... -
很强大的日历
2009-09-03 13:32 12626一个万年历 功能很全,带农历 https://token.l ... -
java技术集合
2009-06-18 12:30 1121java技术集合 -
留言内容转换通用Bean
2009-06-15 13:48 2084package com.web; import ...
相关推荐
几个web以及swing下的及格例子,供初学jfree的朋友熟悉
jfreechart简单实例 jfreechart简单实例 jfreechart简单实例
jFreeChart简单例子主要介绍了jfreechart的简单例子,包括仪表盘、时钟表、条形图和饼图的简单例子
jFreeChart简单入门例子
jfreechart报表组件简单应用实例。熟悉jfreechart的基本用法。
struts1+jfreechart一个简单的小例子,主要和大家分享一下搭起框架的过程。
JFreeChart 教程和例子 ,还有包括安装步骤和JAR包的获取等
jfreechart是个很好用的java图形工具,有的朋友下了他的jar包后不知道如何操作,这里上传一个简单的例子供大家交流
Java图形编程的好东西,入门的好例子,代码整洁规范
下面有两个简单的例子,调用servlet,生成统计图. 条形统计图 href="servlet/ServletDemo1">条形统计图; <!--跳转到ServletDemo1生成条形统计图--> 可以选择统计图类型 href="chart1.html">三种类型 <!--链接到chart...
用于学习JFreeChart的web实例,简单易用,导入到Eclipse后即可使用。
JFreeChart是一组功能强大、灵活易用的Java绘图API,使用它可以生成多种通用性的报表,包括柱状图、饼图、曲线图、甘特图等。它能够用在Swing和Web等中制作自定义的图表或报表,并且得到广泛的应用。本文将通过引领...
jfreechart入门资料及源包(附简单实例)
NULL 博文链接:https://zz563143188.iteye.com/blog/1933112
jfreeChart 例子,并设置语言,防止乱码
struts2整合jfreechart简单实用实例,包含饼状图、柱状图、折线图.
jFreeChart应用,包含web应用及普通应用程序应用,含有jFreeChart所需的jar包及相关教程,还有两个简单的实例源代码,jFreeChart入门很有帮助
Jfreechart封装示例,简单调用即可。
JFreeChart JSP显示柱状图的应用例子,有详细注释说明。所用包,及简单应用教程。