ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:330.71KB ,
资源ID:11883826      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11883826.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(JFreeChart与JSP动态图表.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

JFreeChart与JSP动态图表.docx

1、JFreeChart与JSP动态图表1 下载 http:/www.jfree.org/jfreechart/download.htmljfreechart-1.0.5jarjcommon-1.0.9.jar、gnujaxp.jarweb.xml配置 DisplayChart org.jfree.chart.servlet.DisplayChart DisplayChart /servlet/DisplayChart 生成动态图表步骤: 创建绘图数据集合 创建JFreeChart实例 自定义图表绘制属性,该步可选 生成指定格式的图片,并返回图片名称 组织图片浏览路径 通过HTML中的元素显示图片

2、2 核心类 类名功能JFreeChart图表对象,生成任何类型的图表都要通过该对象,JFreeChart插件提供了一个工厂类ChartFactory,用来创建各种类型的图表对象XXXDataset数据集对象,用来保存绘制图表的数据,不同类型的图表对应着不同类型的数据集对象XXXPlot绘制区对象,如果需要自行定义绘图区的相关绘制属性,需要通过该对象进行设置XXXAxis坐标轴对象,用来定义坐标轴的绘制属性XXXRenderer图片渲染对象,用于渲染和显示图表XXXURLGenerator链接对象,用于生成Web图表中项目的鼠标单击链接XXXToolTipGenrator图表提示对象,用于生成图

3、表提示信息,不同类型的图表对应着不同类型的图表提示对象3 利用DefaultCategoryDataset数据集绘制柱形图package com.mwq.jfreechart;import java.awt.Color;import java.awt.GradientPaint;import java.io.IOException;import javax.servlet.http.HttpSession;import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartRenderingInfo;import org.jfree.

4、chart.JFreeChart;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.CategoryLabelPositions;import org.jfree.chart.entity.StandardEntityCollection;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.renderer.category.BarRendere

5、r;import org.jfree.chart.servlet.ServletUtilities;import org.jfree.chart.title.TextTitle;import org.jfree.data.category.DefaultCategoryDataset;public class DrawHistogram int width;/ 图象宽度 int height; / 图象高度 String chartTitle;/ 图表标题 String subtitle;/ 副标题 String xTitle;/ X轴标题 String yTitle;/ Y轴标题 Strin

6、g cutline;/ 图例名称 String category; / 统计种类 Double data;/ 绘图数据 String servletURI = /servlet/DisplayChart;/ 映射路径 public DrawHistogram() this.width = 450; this.height = 325; this.chartTitle = 编程类图书年销量柱形图分析; this.subtitle = -统计时间:2008年; this.xTitle = 销售季度; this.yTitle = 销售量 单位:万册; this.cutline = new Strin

7、g ASP, JSP, PHP ; this.category = new String 第1季度, 第2季度, 第3季度, 第4季度 ; this.data = new Doublecutline.lengthcategory.length; for (int m = 0; m cutline.length; m+) for (int n = 0; n category.length; n+) datamn = 1 + Math.random() * 100; public DrawHistogram(int width, int height, String chartTitle, Str

8、ing subtitle, String xTitle, String yTitle, String cutline, String category, Double data) this.width = width; this.height = height; this.chartTitle = chartTitle; this.subtitle = subtitle; this.xTitle = xTitle; this.yTitle = yTitle; this.cutline = cutline; this.category = category; this.data = data;

9、public DrawHistogram(int width, int height, String chartTitle, String subtitle, String xTitle, String yTitle, String cutline, String category, Double data, String servletURI) this.width = width; this.height = height; this.chartTitle = chartTitle; this.subtitle = subtitle; this.xTitle = xTitle; this.

10、yTitle = yTitle; this.cutline = cutline; this.category = category; this.data = data; this.servletURI = servletURI; public String draw(HttpSession session, String contextPath) / 创建绘图数据集 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int m = 0; m cutline.length; m+) for (int n = 0

11、; n 0) / 添加副标题 chart.addSubtitle(new TextTitle(subtitle); GradientPaint chartGP = new GradientPaint(0, 0, new Color(219, 227, 251), 0, height, Color.WHITE, false);/ 创建渐变色对象 chart.setBackgroundPaint(chartGP);/ 设置图片背景色 / 通过绘图区对象,可以设置更多的绘图属性 CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgrou

12、ndPaint(new Color(241, 219, 127);/ 设置绘图区背景色 plot.setRangeGridlinePaint(Color.RED);/ 设置水平方向背景线颜色 plot.setRangeGridlinesVisible(true);/ 设置是否显示水平方向背景线,默认值为true plot.setDomainGridlinePaint(Color.RED);/ 设置垂直方向背景线颜色 plot.setDomainGridlinesVisible(true);/ 设置是否显示垂直方向背景线,默认值为false / 通过柱形对象,可以设置柱形的绘图属性 BarRen

13、derer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false);/ 设置是否绘制柱形的轮廓线,默认值为true / 设置填充柱形的渐进色 Color color = new Colorcutline.length; color0 = new Color(99, 99, 0); color1 = new Color(255, 169, 66); color2 = new Color(33, 255, 66); for (int i = 0; i color.length; i+) Gradi

14、entPaint gp = new GradientPaint(0, 0, colori.brighter(), 0, height, colori.darker(); renderer.setSeriesPaint(i, gp); / 设置横轴标题文字的旋转方向 CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); / 自定义图表结束! / 固定用法 ChartRenderingInfo info = new Cha

15、rtRenderingInfo( new StandardEntityCollection(); / 生成指定格式的图片,并返回图片名称 String fileName = ; try fileName = ServletUtilities.saveChartAsPNG(chart, width, height, info, session); catch (IOException e) System.out.println(- 在绘制图片时抛出异常,内容如下:); e.printStackTrace(); / 组织图片浏览路径 String graphURL = contextPath +

16、servletURI + ?filename= + fileName; / 返回图片浏览路径 return graphURL; JSP: 利用DefaultCategoryDataset数据集绘制柱形图     利用DefaultCategoryDataset数据集绘制柱形图   img src= border=1 alt=   % / 如果在绘图数据中存在负数,绘制出的图片将是另一种效果 int width = 450;/ 图象宽度 int height = 325; / 图象高度 String chartTitle = 编程类图书同期销量对比柱形图分

17、析;/ 图表标题 String subtitle = -对比2008年与2007年同期;/ 副标题 String xTitle = 对比季度;/ X轴标题 String yTitle = 增减量 单位:万册;/ Y轴标题 String cutline = new String ASP, JSP, PHP ;/ 图例名称 String category = new String 第1季度, 第2季度, 第3季度, 第4季度 ; / 统计种类 Double data = new Doublecutline.lengthcategory.length;/ 绘图数据 for (int m = 0; m

18、 cutline.length; m+) for (int n = 0; n img src= border=1 alt=     4. 利用XYDataset数据集绘制与日期相关的柱形图package com.mwq.jfreechart;import java.awt.Color;import java.awt.GradientPaint;import java.io.IOException;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.servl

19、et.http.HttpSession;import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartRenderingInfo;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.DateAxis;import org.jfree.chart.axis.DateTickMarkPosition;import org.jfree.chart.entity.StandardEntityCollection;import org.jfree.chart.plot

20、.PlotOrientation;import org.jfree.chart.plot.XYPlot;import org.jfree.chart.servlet.ServletUtilities;import org.jfree.chart.title.TextTitle;import org.jfree.data.time.Month;import org.jfree.data.time.TimeSeries;import org.jfree.data.time.TimeSeriesCollection;import org.jfree.data.time.Year;import org

21、.jfree.data.xy.IntervalXYDataset;public class DrawHistogram int width;/ 图象宽度 int height; / 图象高度 String chartTitle;/ 图表标题 String subtitle;/ 副标题 String xTitle;/ X轴标题 String yTitle;/ Y轴标题 Map data;/ 绘图数据 String servletURI = /servlet/DisplayChart;/ 映射路径 public DrawHistogram() this.width = 450; this.heig

22、ht = 325; this.chartTitle = 倾诚科技年销售额柱形图分析; this.subtitle = -统计时间:2008年; this.xTitle = 统计月份; this.yTitle = 销售额 单位:万元; this.data = new HashMap(); for (int i = 1; i 13; i+) data.put(i, 1 + Math.random() * 100); public DrawHistogram(int width, int height, String chartTitle, String subtitle, String title

23、, String title2, Map data) super(); this.width = width; this.height = height; this.chartTitle = chartTitle; this.subtitle = subtitle; xTitle = title; yTitle = title2; this.data = data; public String draw(HttpSession session, String contextPath) / 创建绘图数据集 TimeSeries timeSeries = new TimeSeries(chartTitle, xTitle, yTitle, Month.class); Iterator it = data.keySet().iterator(); while (it.hasNext() int key = (Integer) it.next(); timeSeries.add(new Mon

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1