欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    jfreechart 线图 柱图 饼图 散点图.doc

    • 资源ID:34411448       资源大小:27.15KB        全文页数:25页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    jfreechart 线图 柱图 饼图 散点图.doc

    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; i<datas.length; i+) if (datasi.length=0) cddata.setValue(null, "", categoryKeysi); else for (int j=0; j<datasi.length; j+) cddata.setValue(datasij, descriptionKeysj, categoryKeysi);/*数据System.out.println("*datas begin: *");for (int i=0; i<datas.length; i+) for (int j=0; j<datasi.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; i<descriptionKeys.length; i+) for (int j=0; j<datas.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; i<descriptionKeys.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; i<datas.length; i+) if (datasi.length=0) cddata.setValue(null, "", categoryKeysi); else for (int j=0; j<datasi.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; i<data.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; i<datas.length; i+) if (datasi.length=0) cddata.setValue(null, "", categoryKeysi); else for (int j=0; j<datasi.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(Map<String, Map<Double,Double>> 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(Map<String, Map<String,Double>> 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(Map<String, Map<String,Double>> 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(Map<String, Map<String,Double>> 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); /

    注意事项

    本文(jfreechart 线图 柱图 饼图 散点图.doc)为本站会员(豆****)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开