




已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
public abstract class ChartAction extends BaseAction public JFreeChart chart;private String descriptionKeys;private String categoryKeys;private Double datas;private DefaultCategoryDataset cddata;private DefaultPieDataset dpdata;private XYDataset xydata;private IntervalXYDataset ixydata;private String title;/标题private String x;/横坐标名称private String y;/纵坐标名称private String y2; / 纵坐标名称2/* * 线图 */public void createLineChart() /设置数据cddata = new DefaultCategoryDataset();for (int i=0; idatas.length; i+) if (datasi.length=0) cddata.setValue(null, , categoryKeysi); else for (int j=0; jdatasi.length; j+) cddata.setValue(datasij, descriptionKeysj, categoryKeysi);/*数据System.out.println(*datas begin: *);for (int i=0; idatas.length; i+) for (int j=0; jdatasi.length; j+) System.out.println(categoryKeysi + : + descriptionKeysj + | + datasij);System.out.println(*datas end: *);*/chart = ChartFactory.createLineChart(title, / 图表标题x,/ 目录轴的显示标签y,/ 数值轴的显示标签cddata,/ 数据集 PlotOrientation.VERTICAL, / 图表方向:水平、垂直 true, / 是否显示图例(对于简单的柱状图必须是false)true, / 是否生成工具 false);/ 是否生成URL链接 CategoryPlot plot = chart.getCategoryPlot();plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setDomainGridlinePaint(Color.lightGray);/设置垂直网格线的颜色plot.setRangeGridlinePaint(Color.lightGray);/设置水平网格线的颜色plot.setDomainGridlinesVisible(true); /设置垂直网格线是否显示plot.setRangeGridlinesVisible(true); /设置水平网格线是否显示LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer)plot.getRenderer();lineandshaperenderer.setBaseShapesVisible(true);lineandshaperenderer.setBaseShapesFilled(true);chart.setBackgroundPaint(Color.white);setChartFont();/* * 饼图 */public void createPieChart() dpdata = new DefaultPieDataset();/生成JFreeChart对象Double d = 0.0;for (int i=0; idescriptionKeys.length; i+) for (int j=0; jdatas.length; j+) d = d + (datasji=null?0:datasji);dpdata.setValue(descriptionKeysi, d.doubleValue();chart = ChartFactory.createPieChart(title, dpdata, true, true, true);PiePlot plot = (PiePlot)chart.getPlot();plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setNoDataMessage(没有数据!); plot.setLabelGenerator(new StandardPieSectionLabelGenerator( (0: (2), NumberFormat.getNumberInstance(), new DecimalFormat(0.00%); chart.setBackgroundPaint(Color.white);setChartFont(PieChart);/* * 饼图 */public void createPieChartValue(Double value) dpdata = new DefaultPieDataset();/生成JFreeChart对象 for (int i=0; idescriptionKeys.length; i+) dpdata.setValue(descriptionKeysi, valuei);chart = ChartFactory.createPieChart(title, dpdata, true, true, true);PiePlot plot = (PiePlot)chart.getPlot();plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setNoDataMessage(没有数据!); plot.setLabelGenerator(null); plot.setToolTipGenerator(new StandardPieToolTipGenerator(0), NumberFormat.getNumberInstance(), new DecimalFormat(0.00%); LegendTitle legend = chart.getLegend(); legend.setBackgroundPaint(new Color(238, 244, 255);/图例背景 legend.setItemFont(new Font(宋体, Font.ITALIC, 12); / 图例的字体 legend.setPosition(RectangleEdge.RIGHT);/图例位置 legend.setHeight(1000.00);chart.setBackgroundPaint(Color.white);setChartFont(PieChart);/* * 柱图 */public void createBarChart() /设置数据cddata = new DefaultCategoryDataset();for (int i=0; idatas.length; i+) if (datasi.length=0) cddata.setValue(null, , categoryKeysi); else for (int j=0; jdatasi.length; j+) cddata.setValue(datasij, descriptionKeysj, categoryKeysi);chart = ChartFactory.createBarChart(title, / 图表标题x, / 目录轴的显示标签y, / 数值轴的显示标签cddata, / 数据集PlotOrientation.VERTICAL, / 图表方向:水平、垂直true, / 是否显示图例(对于简单的柱状图必须是false)true, / 是否生成工具false / 是否生成URL链接);CategoryPlot plot = chart.getCategoryPlot();plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色chart.setBackgroundPaint(Color.white);setChartFont();/* * 柱图 */public void createBarChart3D(Object data) /设置数据cddata = new DefaultCategoryDataset();for (int i=0; idata.length; i+) cddata.setValue(Number)datai, categoryKeysi, categoryKeysi);chart = ChartFactory.createBarChart3D(title, / 图表标题x, / 目录轴的显示标签y, / 数值轴的显示标签cddata, / 数据集PlotOrientation.VERTICAL, / 图表方向:水平、垂直true, / 是否显示图例(对于简单的柱状图必须是false)true, / 是否生成工具false / 是否生成URL链接);CategoryPlot plot = chart.getCategoryPlot();plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色chart.setBackgroundPaint(Color.white);setChartFont();/* * 对比柱状图 */public void createBarChart(CategoryDataset dataset) chart = ChartFactory.createBarChart(title, / 图表标题x, / 目录轴的显示标签y, / 数值轴的显示标签dataset, / 数据集PlotOrientation.VERTICAL, / 图表方向:水平、垂直true, / 是否显示图例(对于简单的柱状图必须是false)true, / 是否生成工具false / 是否生成URL链接);CategoryPlot plot = chart.getCategoryPlot();plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色chart.setBackgroundPaint(Color.white);setChartFont();/* * 面积图 */public void createAreaChart() /设置数据cddata = new DefaultCategoryDataset();cddata = new DefaultCategoryDataset(); for (int i=0; idatas.length; i+) if (datasi.length=0) cddata.setValue(null, , categoryKeysi); else for (int j=0; jdatasi.length; j+) cddata.setValue(datasij, descriptionKeysj, categoryKeysi);chart = ChartFactory.createAreaChart(title, / 图表标题x, / 目录轴的显示标签y, / 数值轴的显示标签cddata, / 数据集PlotOrientation.VERTICAL, / 图表方向:水平、垂直true, / 是否显示图例(对于简单的柱状图必须是false)true, / 是否生成工具false / 是否生成URL链接); CategoryPlot plot = chart.getCategoryPlot();plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色chart.setBackgroundPaint(Color.white);setChartFont(); /* * X,Y 线图chart * param chartMap */public void createXYLineChart(MapString, Map chartMap) /创建XYDataset对象(准备数据) xydata = createXYDataset(chartMap); / 创建JFreeChart对象:ChartFactory.createXYLineChart chart = ChartFactory.createXYLineChart(title, / 标题 x, / categoryAxisLabel (category轴,横轴,X轴标签) y, / valueAxisLabel(value轴,纵轴,Y轴的标签) xydata, / dataset PlotOrientation.VERTICAL, true, / legend true, / tooltips true); / URLs / 使用CategoryPlot设置各种参数。以下设置可以省略。 XYPlot plot = (XYPlot) chart.getPlot(); /x轴整数显示 NumberAxis na= (NumberAxis)plot.getDomainAxis(); na.setStandardTickUnits(NumberAxis.createIntegerTickUnits(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseItemLabelsVisible(true); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true);plot.setRenderer(0, renderer);plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setDomainGridlinePaint(Color.lightGray);/设置垂直网格线的颜色plot.setRangeGridlinePaint(Color.lightGray);/设置水平网格线的颜色plot.setDomainGridlinesVisible(true); /设置垂直网格线是否显示plot.setRangeGridlinesVisible(true); /设置水平网格线是否显示chart.setBackgroundPaint(Color.white);setChartFont(XYChart); /* * 双y轴 曲线图,没有折线点 * param cddata */public void createXYsLineChart(DefaultCategoryDataset cddataLeft,DefaultCategoryDataset cddataRight) / 设置字体样式Font fs = new Font(微软雅黑, Font.BOLD, 12);Font f = new Font(微软雅黑, Font.PLAIN, 12);/ 创建JFreeChart对象:ChartFactory.createXYLineChart chart = ChartFactory.createLineChart(title, / 标题 x, / categoryAxisLabel (category轴,横轴,X轴标签) y, / valueAxisLabel(value轴,纵轴,Y轴的标签) cddataLeft, / dataset PlotOrientation.VERTICAL, true, / legend true, / tooltips true); / URLs / 使用CategoryPlot设置各种参数。以下设置可以省略。 CategoryPlot plot = (CategoryPlot) chart.getPlot(); /设置X坐标的显示方式(默认水平)CategoryAxis categoryaxis = plot.getDomainAxis();categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);categoryaxis.setCategoryMargin(9);/ 分类轴边距/ 左边y轴显示方式/NumberAxis numberaxis= (NumberAxis)plotxy.getRangeAxis();/y轴整数显示 NumberAxis numberaxis = new NumberAxis(this.y);numberaxis.setLabelFont(fs);numberaxis.setTickLabelFont(f);plot.setRangeAxis(0, numberaxis);/ 右边y轴显示方式NumberAxis numberaxis2 = new NumberAxis(this.y2);numberaxis2.setLabelFont(fs);numberaxis2.setTickLabelFont(f);plot.setRangeAxis(1, numberaxis2);plot.setDataset(1, cddataRight);plot.mapDatasetToRangeAxis(1, 1); /y轴(左边)LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();renderer.setBaseItemLabelsVisible(true); plot.setRenderer(0, renderer);renderer.setSeriesStroke(0, new BasicStroke(1.6F); /y轴(右边),绘制单元对象 LineAndShapeRendererLineAndShapeRenderer renderer2 = new LineAndShapeRenderer();plot.setRenderer(1, renderer2); /设置图标是否可见renderer2.setBaseShapesVisible(false); /是否显示端点renderer2.setBaseItemLabelsVisible(true);renderer2.setBaseLinesVisible(true);renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(); /鼠标动态显示数据 renderer2.setSeriesStroke(0, new BasicStroke(1.6F); /加粗线条plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setDomainGridlinePaint(Color.lightGray);/设置垂直网格线的颜色plot.setRangeGridlinePaint(Color.lightGray);/设置水平网格线的颜色plot.setDomainGridlinesVisible(true); /设置垂直网格线是否显示plot.setRangeGridlinesVisible(true); /设置水平网格线是否显示chart.setBackgroundPaint(Color.white);setChartFont(cateRealChart); /* * 时间 线图 * param chartMap */public void createXYTimeChart(MapString, Map chartMap) /创建XYDataset对象(准备数据) xydata = createXYTimeDataset(chartMap); / 创建JFreeChart对象:ChartFactory.createXYLineChart chart = ChartFactory.createTimeSeriesChart(title, / 标题 x, / categoryAxisLabel (category轴,横轴,X轴标签) y, / valueAxisLabel(value轴,纵轴,Y轴的标签) xydata, / dataset true, / legend true, / tooltips true); / URLs / 使用CategoryPlot设置各种参数。以下设置可以省略。 XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();xylineandshaperenderer.setBaseShapesVisible(false);xylineandshaperenderer.setBaseShapesFilled(true);DateAxis dateaxis = (DateAxis)plot.getDomainAxis();/时间轴垂直dateaxis.setVerticalTickLabels(true);/时间轴间距是15分钟,格式为小时:分钟 int count=15;SimpleDateFormat formatter = new SimpleDateFormat(yyyy-MM-dd HH:mm);dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.MINUTE, count, formatter);dateaxis.setDateFormatOverride(formatter); plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setDomainGridlinePaint(Color.lightGray);/设置垂直网格线的颜色plot.setRangeGridlinePaint(Color.lightGray);/设置水平网格线的颜色plot.setDomainGridlinesVisible(true); /设置垂直网格线是否显示plot.setRangeGridlinesVisible(true); /设置水平网格线是否显示chart.setBackgroundPaint(Color.white);setChartFont(XYChart); /* * 时间线图数据集 * param chartMap * return */private XYDataset createXYTimeDataset(MapString, Map chartMap) TimeSeriesCollection tseriesCollection = new TimeSeriesCollection(); for(Object m: chartMap.keySet() TimeSeries tseries = new TimeSeries(String)m); for(String n: chartMap.get(m).keySet() tseries.add(new Minute(DateUtil.getDateFromStrFull(n), chartMap.get(m).get(n); tseriesCollection.addSeries(tseries); return tseriesCollection;/* * 时间 线图 * param chartMap */public void createXYTimeChartMinute(MapString, Map chartMap,int interval) /创建XYDataset对象(准备数据) xydata = createXYTimeDataset(chartMap); / 创建JFreeChart对象:ChartFactory.createXYLineChart chart = ChartFactory.createTimeSeriesChart(title, / 标题 x, / categoryAxisLabel (category轴,横轴,X轴标签) y, / valueAxisLabel(value轴,纵轴,Y轴的标签) xydata, / dataset true, / legend true, / tooltips true); / URLs / 使用CategoryPlot设置各种参数。以下设置可以省略。 XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();xylineandshaperenderer.setBaseShapesVisible(true);xylineandshaperenderer.setBaseShapesFilled(true);DateAxis dateaxis = (DateAxis)plot.getDomainAxis();/时间轴垂直dateaxis.setVerticalTickLabels(true);/时间轴间距是15分钟,格式为小时:分钟SimpleDateFormat formatter = new SimpleDateFormat(HH:mm);dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.MINUTE, interval, formatter);dateaxis.setDateFormatOverride(formatter);/y轴刻度属性NumberAxis numAxis = (NumberAxis)plot.getRangeAxis();numAxis.setNumberFormatOverride(new DecimalFormat(0.0); /y轴刻度保留一位 plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setDomainGridlinePaint(Color.lightGray);/设置垂直网格线的颜色plot.setRangeGridlinePaint(Color.lightGray);/设置水平网格线的颜色plot.setDomainGridlinesVisible(true); /设置垂直网格线是否显示plot.setRangeGridlinesVisible(true); /设置水平网格线是否显示chart.setBackgroundPaint(Color.white);setChartFont(XYChart); public void createXYLineTimeDayChart(MapString, Map chartMap) /创建XYDataset对象(准备数据) xydata = createXYTimeDataset(chartMap); / 创建JFreeChart对象:ChartFactory.createXYLineChart chart = ChartFactory.createTimeSeriesChart(title, / 标题 x, / categoryAxisLabel (category轴,横轴,X轴标签) y, / valueAxisLabel(value轴,纵轴,Y轴的标签) xydata, / dataset true, / legend true, / tooltips true); / URLs / 使用CategoryPlot设置各种参数。以下设置可以省略。 XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();xylineandshaperenderer.setBaseShapesVisible(false);xylineandshaperenderer.setBaseShapesFilled(true);xylineandshaperenderer.setSeriesStroke(2,new BasicStroke(4F); /加粗线条xylineandshaperenderer.setSeriesStroke(1,new BasicStroke(1.5F); /加粗线条xylineandshaperenderer.setSeriesStroke(0,new BasicStroke(1.5F); /加粗线条DateAxis dateaxis = (DateAxis)plot.getDomainAxis();/时间轴垂直/dateaxis.setVerticalTickLabels(true);/设置距离图片左端距离dateaxis.setLowerMargin(0.1);/设置距离图片右端距离dateaxis.setUpperMargin(0.1);/时间轴间距是12小时 int count=14;SimpleDateFormat formatter = new SimpleDateFormat(yyyy-MM-dd HH:mm);dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, count, formatter);dateaxis.setDateFormatOverride(formatter);/y轴刻度属性NumberAxis numAxis = (NumberAxis)plot.getRangeAxis();numAxis.setNumberFormatOverride(new DecimalFormat(0.0); /y轴刻度保留一位 plot.setBackgroundPaint(new Color(238, 244, 255);/设置图表的颜色plot.setDomainGridlinePaint(Color.lightGray);/设置垂直网格线的颜色plot.setRangeGridlinePaint(Color.lightGray);/设置水平网格线的颜色plot.setDomainGridlinesVisible(true); /设置垂直网格线是否显示plot.setRangeGridlinesVisible(true); /设置水平网格线是否显示chart.setBackgroundPaint(Color.white);setChartFont(XYChart); /* * 短期预测 * param chartMap */public void createXYLineTimeDayShortChart(MapString, Map chartMap,int count,boolean flag) /创建XYDataset对象(准备数据) xydata = createXYTimeDataset(chartMap); / 创建JFreeChart对象:ChartFactory.createXYLineChart chart = ChartFactory.createTimeSeriesChart(title, / 标题 x, / categoryAxisLabel (category轴,横轴,X轴标签) y, / valueAxisLabel(value轴,纵轴,Y轴的标签) xydata, / dataset true, / legend true, / tooltips true); / URLs / 使用CategoryPlot设置各种参数。以下设置可以省略。 XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.get
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 面案等级考试及答案
- 主体剪力墙模板施工方案
- 旅行社运营实务(第二版)习题及答案 项目四 习题
- 2025年国企会计考试题目及答案
- 慢性肾功能衰竭课件
- 慕课课件观看时长建议
- 弱电设备采购规范书六安
- 酒钢公司考试题及答案
- 竞聘店长考试题目及答案
- 软件技能考试模拟题及答案
- GB/T 19355.2-2016锌覆盖层钢铁结构防腐蚀的指南和建议第2部分:热浸镀锌
- 主编-孙晓岭组织行为学-课件
- 核心素养视角下教师专业发展课件
- 企业信用信息公告系统年度报告模板:非私营其他企业
- 施工员钢筋工程知识培训(培训)课件
- 质量管理体系审核中常见的不合格项
- 共用水电费分割单模板
- 《阿房宫赋》全篇覆盖理解性默写
- 学校体育学(第三版)ppt全套教学课件
- NCStudioGen6A编程手册
- 胸痛中心各项管理制度汇编(2022年)
评论
0/150
提交评论