免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实例代码:这里不介绍JfreeChar的配置import java.awt.Font;import java.awt.Rectangle;import java.awt.Shape;import java.io.PrintWriter;import java.io.StringReader;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.dom4j.Document;import org.dom4j.Element;import org.dom4j.io.SAXReader;import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartRenderingInfo;import org.jfree.chart.ChartUtilities;import org.jfree.chart.JFreeChart;import org.jfree.chart.StandardChartTheme;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.CategoryLabelPositions;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.entity.ChartEntity;import org.jfree.chart.entity.StandardEntityCollection;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.xml.sax.InputSource;public class MyJFreeChar /* * 生成图表 返回图片信息 * param response * param request * return */SuppressWarnings(unchecked)public static Map getFileInfo(HttpServletResponse response,HttpServletRequest request)Map file = new HashMap();String imgName = null;/生成的图表图片文件名String imgSrc = null;/生成的图表图片文件地址String title = 图表上方标题;String bottomTitle = X轴正文标题;String leftTitle = Y轴左侧标题;String imgUseMapStr = null;int labelPosition = 0;/X轴下标字体显示角度int width = 500;/图表宽度 int height = 300;/图表高度 boolean isShowDataName = true;/在X轴下方是否显示柱体属性信息try response.setContentType(text/html); response.setCharacterEncoding(UTF-8);StandardChartTheme standardChartTheme = new StandardChartTheme(CN);standardChartTheme.setExtraLargeFont(new Font(隶书, Font.BOLD, 20);/设置标题字体standardChartTheme.setRegularFont(new Font(宋书, Font.PLAIN, 15);/设置图例的字体standardChartTheme.setLargeFont(new Font(宋书, Font.PLAIN, 15);/ 设置轴向的字体ChartFactory.setChartTheme(standardChartTheme);/ 应用主题样式DefaultCategoryDataset dataset = new DefaultCategoryDataset();/图表数据 /组内不再分属性/dataset.addValue(10, 组属性 , 第1组); /dataset.addValue(80, 组属性 , 第2组); /dataset.addValue(50, 组属性 , 第3组); /dataset.addValue(30, 组属性 , 第4组);/组内分属性dataset.addValue(80, 第1个属性 , 第1组);dataset.addValue(50, 第1个属性 , 第2组); dataset.addValue(40, 第2个属性 , 第1组); dataset.addValue(30, 第2个属性 , 第2组);dataset.addValue(60, 第3个属性 , 第1组); dataset.addValue(20, 第3个属性 , 第2组);/生成图表JFreeChart chart = ChartFactory.createBarChart3D(title,bottomTitle,leftTitle,dataset,PlotOrientation.VERTICAL,isShowDataName,true,true);/设置样式CategoryPlot plot = chart.getCategoryPlot();CategoryAxis domainAxis = plot.getDomainAxis();switch(labelPosition)case 0:domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);/标准样式break;case 45:domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);/正向旋转45度break;case 90:domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);/正向旋转90度break;case -45:domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);/反向旋转45度break;case -90:domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);/反向旋转90度break;plot.setDomainAxis(domainAxis);ValueAxis rangeAxis = plot.getRangeAxis();rangeAxis.setUpperMargin(0.15);/设置最高的一个 Item 与图片顶端的距离rangeAxis.setLowerMargin(0.15);/设置最低的一个 Item 与图片底端的距离rangeAxis.setLowerBound(0);/设置Y轴的最小值/rangeAxis.setUpperBound(600);/设置Y轴的最大值PrintWriter writer = response.getWriter(); Shape shape = new Rectangle(10, 5); ChartEntity entity = new ChartEntity(shape); StandardEntityCollection coll = new StandardEntityCollection(); coll.add(entity); ChartRenderingInfo info = new ChartRenderingInfo(coll); imgName = ServletUtilities.saveChartAsPNG(chart,width,height,info,request.getSession(); imgSrc = request.getContextPath() + /char/jfreechar?filename=+ imgName;/“/char/jfreechar?filename=”这个地址要和配置文件里配置的一致/-重写Map-修改热点提示信息和点击后的链接地址-imgUseMapStr = ChartUtilities.getImageMap(imgName, info);StringReader reader = new StringReader(imgUseMapStr); InputSource source = new InputSource(reader); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(source); Element root = document.getRootElement(); List childList = root.elements(area); for(int i=0; ichildList.size(); i+) Element e = childList.get(i); e.remove(e.attribute(title); e.remove(e.attribute(href); e.addAttribute(title, 自定义提示信息1n自定义提示信息2); e.addAttribute(href, request.getContextPath();/自定义点击热点后的
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 某纺织厂生产安全防护规范
- 猪轮状病毒与猪流行性腹泻病毒病原学特征比较研究
- 餐饮服务、入网餐饮(非食品自动设备制售)安装要求
- 某家具厂组装工艺管理细则
- 2026年传统优势产业提品质创品牌知识题
- 2026年燃气场站防雷防静电接地装置定期检测及维护题库
- 2026年艺术概论与技能综合训练题
- 2026年黑龙江单招健康管理专业综合素养考核题库
- 2026年水利系统河道防洪管理知识测试题
- 2026年世界地理奇观趣味知识题库
- 覆膜加工协议书
- 2025年国家公务员综合性消防救援面试题及答案
- 妇科恶性肿瘤术后盆腔功能与生活质量评估方案
- 船体装配工工艺作业技术规程
- 物探工岗前生产安全培训考核试卷含答案
- 通信客服培训课件
- 气瓶运输知识培训内容课件
- 全过程工程咨询能力评价指标
- 人工水磨钻劳务合同范本
- 北京卷2025年高考生物真题含解析
- 2025年村级水管员应聘笔试技巧与策略
评论
0/150
提交评论