- 浏览: 50685 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
geeksun:
按照代码运行的结果是空指针,方便给一份完整的代码出来吗?
事件驱动工具RRibbit使用 -
LinApex:
Rribbit啥东西
基于Rribbit和Spring MVC搭建REST风格架构 -
liangzi4454:
PD4ML -
zgpinguo:
全篇代码,没有任何笔记。。。
JFreeChart 笔记
package org.ems.core.utils; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.io.OutputStream; import java.text.DecimalFormat; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.DialShape; import org.jfree.chart.plot.MeterInterval; import org.jfree.chart.plot.MeterPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.plot.dial.DialBackground; import org.jfree.chart.plot.dial.DialCap; import org.jfree.chart.plot.dial.DialPlot; import org.jfree.chart.plot.dial.StandardDialFrame; import org.jfree.chart.plot.dial.StandardDialRange; import org.jfree.chart.plot.dial.StandardDialScale; import org.jfree.chart.plot.dial.DialPointer.Pointer; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DefaultValueDataset; import org.jfree.data.xy.XYDataset; import org.jfree.ui.GradientPaintTransformType; import org.jfree.ui.StandardGradientPaintTransformer; /** * Util class to generate report chart. * * @Class: JFreeChartUtil.java * @author: wangxiang * @create date: 2012-01-04 * */ public class JFreeChartUtil { private static Font font_12 = new Font("宋体", Font.PLAIN, 12); private static Font font_16 = new Font("宋体", Font.PLAIN, 16); /** * Generate line shape chart * * @param os * @param width * @param height * @param title * @param xAxisLabel * @param yAxisLabel * @param dataset * @param legend * @param tooltips * @param urls * @throws Exception */ public static void generateLineShapeChart(OutputStream os, int width, int height, String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls, double rangeTick, double startValue) throws Exception { JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setBackgroundPaint(new Color(218, 229, 240)); XYPlot plot = chart.getXYPlot(); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.red); NumberAxis vn = (NumberAxis) plot.getRangeAxis(); vn.setAutoRangeIncludesZero(true); DecimalFormat df = new DecimalFormat("#0"); vn.setNumberFormatOverride(df); vn.setAutoTickUnitSelection(false); vn.setLabelFont(font_12); vn.setLabel("分数"); vn.setTickUnit(new NumberTickUnit(rangeTick)); vn.setLowerBound(startValue); ValueAxis va = plot.getDomainAxis(); va.setAutoRange(false); va.setAutoTickUnitSelection(false); va.setLabelFont(font_12); va.setLabel("年份"); plot.setDomainAxis(va); plot.setBackgroundPaint(new Color(184, 220, 254)); plot.setNoDataMessageFont(font_16); plot.setNoDataMessage("找不到数据。"); chart.setTitle("纵向比较图表"); XYLineAndShapeRenderer lasr = (XYLineAndShapeRenderer) plot.getRenderer(); lasr.setSeriesFillPaint(0, Color.RED); lasr.setSeriesStroke(0, new BasicStroke(3f)); ChartUtilities.writeChartAsJPEG(os, chart, width, height); } /** * Generate bar shape chart * * @param os * @param width * @param height * @param title * @param categoryAxisLabel * @param valueAxisLabel * @param dataset * @param legend * @param tooltips * @param urls * @throws Exception */ public static void generateBarShapeChart(OutputStream os, int width, int height, String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, boolean legend, boolean tooltips, boolean urls, double rangeTick, double startValue) throws Exception { JFreeChart chart = ChartFactory.createBarChart3D(title, categoryAxisLabel, valueAxisLabel, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls); chart.setBackgroundPaint(new Color(218, 229, 240)); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.red); NumberAxis vn = (NumberAxis) plot.getRangeAxis(); vn.setAutoRangeIncludesZero(true); vn.setLabelFont(font_12); vn.setLabel("指数"); vn.setTickUnit(new NumberTickUnit(rangeTick)); vn.setLowerBound(startValue); CategoryAxis ca = plot.getDomainAxis(); ca.setLabelFont(font_12); ca.setLabel("年份"); plot.setBackgroundPaint(new Color(184, 220, 254)); plot.setNoDataMessageFont(font_16); plot.setNoDataMessage("找不到数据。"); chart.setTitle("横向比较图表"); chart.getLegend().setItemFont(font_12); ChartUtilities.writeChartAsJPEG(os, chart, width, height); } /** * Generate dial plot chart * * @param os * @param width * @param height * @param title * @param currentValue * @param targetValue * @throws Exception */ public static void generateDialPlotShapeChart(OutputStream os, int width, int height, String title, double currentValue, double targetValue) throws Exception { DefaultValueDataset ds1 = new DefaultValueDataset(currentValue); DefaultValueDataset ds2 = new DefaultValueDataset(targetValue); DialPlot dialplot = new DialPlot(); dialplot.setView(0.0, 0.0, 1.0, 0.55); dialplot.setDataset(0, ds1); dialplot.setDataset(1, ds2); StandardDialFrame standarddialframe = new StandardDialFrame(); standarddialframe.setBackgroundPaint(Color.red); standarddialframe.setForegroundPaint(Color.green); dialplot.setDialFrame(standarddialframe); DialBackground dialbackground = new DialBackground(new Color(184, 220, 254)); dialbackground.setGradientPaintTransformer( new StandardGradientPaintTransformer( GradientPaintTransformType.VERTICAL)); dialplot.setBackground(dialbackground); StandardDialScale standarddialscale = new StandardDialScale(0D, 100D, 0D, 180D, 10D, 0); standarddialscale.setFirstTickLabelVisible(false); standarddialscale.setMajorTickIncrement(10D); standarddialscale.setTickRadius(0.88D); standarddialscale.setTickLabelOffset(0.14999999999999999D); standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14)); dialplot.addScale(0, standarddialscale); StandardDialScale standarddialscale1 = new StandardDialScale(0D, 100D, 0D, 180D, 10D, 0); standarddialscale1.setVisible(false); standarddialscale1.setMajorTickIncrement(10D); standarddialscale1.setTickRadius(0.68000000000000005D); standarddialscale1.setTickLabelOffset(0.14999999999999999D); standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 14)); dialplot.addScale(1, standarddialscale1); StandardDialRange standarddialrange = new StandardDialRange(0D, 60D, new Color(255, 0, 0, 255)); standarddialrange.setInnerRadius(0.52000000000000002D); standarddialrange.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange); StandardDialRange standarddialrange1 = new StandardDialRange(60D, 70D, new Color(255, 127, 0, 255)); standarddialrange1.setInnerRadius(0.52000000000000002D); standarddialrange1.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange1); StandardDialRange standarddialrange2 = new StandardDialRange(70D, 80D, Color.YELLOW); standarddialrange2.setInnerRadius(0.52000000000000002D); standarddialrange2.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange2); StandardDialRange standarddialrange3 = new StandardDialRange(80D, 90D, new Color(172, 250, 5)); standarddialrange3.setInnerRadius(0.52000000000000002D); standarddialrange3.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange3); StandardDialRange standarddialrange4 = new StandardDialRange(90D, 100D, new Color(0, 255, 0, 255)); standarddialrange4.setInnerRadius(0.52000000000000002D); standarddialrange4.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange4); Pointer pointer = new Pointer(0); pointer.setRadius(0.5D); dialplot.addLayer(pointer); dialplot.mapDatasetToScale(1, 1); Pointer pointer1 = new Pointer(1); dialplot.addLayer(pointer1); DialCap dialcap = new DialCap(); dialcap.setRadius(0.05D); dialplot.setCap(dialcap); dialplot.setNoDataMessageFont(font_16); dialplot.setNoDataMessage("找不到数据。"); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, dialplot, true); chart.setBackgroundPaint(new Color(218, 229, 240)); chart.setTitle("与上级单位比较图表"); ChartUtilities.writeChartAsJPEG(os, chart, width, height); } public static void generateAlarmDialPlotShapeChart(OutputStream os, int width, int height, String title, double currentValue) throws Exception { MeterPlot meterplot = new MeterPlot(new DefaultValueDataset(currentValue)); meterplot.setRange(new Range(0.0D, 100D)); meterplot.addInterval(new MeterInterval("巨警", new Range(0.0D, 60D), Color.RED, new BasicStroke(2.0F), new Color(255, 0, 0, 255))); meterplot.addInterval(new MeterInterval("重警", new Range(60D, 70D), Color.ORANGE, new BasicStroke(2.0F), new Color(255, 127, 0, 255))); meterplot.addInterval(new MeterInterval("中警", new Range(70D, 80D), Color.YELLOW, new BasicStroke(2.0F), new Color(255, 255, 0, 255))); meterplot.addInterval(new MeterInterval("轻警 ", new Range(80D, 90D), new Color(172, 250, 5), new BasicStroke(2.0F), new Color(172, 250, 5, 255))); meterplot.addInterval(new MeterInterval("无警", new Range(90D, 100D), Color.GREEN, new BasicStroke(2.0F), new Color(0, 255, 0, 255))); meterplot.setNeedlePaint(Color.darkGray); meterplot.setDialBackgroundPaint(Color.white); meterplot.setDialOutlinePaint(Color.gray); meterplot.setDialShape(DialShape.CHORD); meterplot.setMeterAngle(260); meterplot.setTickLabelsVisible(true); meterplot.setTickLabelFont(new Font(" Dialog ", 1, 10)); meterplot.setTickLabelPaint(Color.darkGray); meterplot.setTickSize(10D); meterplot.setTickPaint(Color.lightGray); meterplot.setValuePaint(Color.black); meterplot.setValueFont(new Font(" Dialog ", 1, 14)); meterplot.setNoDataMessageFont(font_16); meterplot.setNoDataMessage("找不到数据。"); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, meterplot, true); chart.setBackgroundPaint(new Color(218, 229, 240)); chart.setTitle("预警图表"); ChartUtilities.writeChartAsJPEG(os, chart, width, height); } }
发表评论
-
Rribbit 与Weblogic集成
2015-11-09 09:56 925Rribbit不支持直接部署进Weblogic,原因在于We ... -
基于Rribbit和Spring MVC搭建REST风格架构
2014-09-22 14:35 1902基于Rribbit事件驱动和Spring MVC搭建Rest ... -
事件驱动工具RRibbit使用
2014-09-22 14:02 1274事件驱动设计可以有效降低模块间耦合度。 添加Rrib ... -
Velocity Replacement
2012-11-01 10:21 1034package com.wx.test; imp ... -
Apache Active MQ 之Queue
2011-03-23 09:10 1081Apache Active MQ 之Queue Pre-Co ... -
Apache Active MQ 之Topic
2011-03-23 09:03 1095Apache Active MQ 之Topic: Pre-C ... -
Java中获取Server内存使用信息
2010-10-29 16:42 1115OperatingSystemMXBean osmb = (O ...
相关推荐
JfreeChart则是一个强大的Java图表库,能够帮助开发者创建各种类型的图表,如饼图、柱状图、线图等,广泛应用于数据分析和展示。 在Struts框架中扩展JfreeChart,主要是为了在Web应用中生成动态的、交互式的图表,...
**JFreeChart 深度解析** JFreeChart 是一个流行的 Java 图表库,它提供了丰富的图表类型,如柱状图、饼图、线图、散点图、面积图、甘特图等,用于数据可视化。这个库在 Java 开发中广泛应用于报表系统、数据分析...
在本篇“JFreeChart学习笔记3-简单Line图形创建”中,我们将深入探讨如何使用JFreeChart库在Java环境中创建基本的线性图表。JFreeChart是一个强大的、开源的Java图表库,它允许开发者轻松地生成各种类型的图表,包括...
这个教程将帮助你深入理解和使用 JFreeChart,结合学习笔记、流程图和示例代码,你可以全面掌握 JFreeChart 的核心概念和实践技巧。 首先,我们从 `jfreechart学习笔记.doc` 入手,这份文档应该包含了关于 ...
《JFreeChart学习详解》 JFreeChart是一个强大的Java库,用于生成高质量的图表,包括折线图、柱状图、饼图、散点图等多种类型。它在各种应用程序中广泛应用,尤其适合于Web应用程序中数据可视化的实现。本文将通过...
**JFreeChart学习笔记1 - 简单Pie图创建** 在Java开发中,我们经常需要展示数据,而饼图(Pie Chart)是一种常见的数据可视化工具,尤其适用于展示各项比例关系。JFreeChart是一个强大的开源Java图表库,它提供了...
### JfreeChart 学习笔记:深度解析与应用 #### JFreeChart概览与核心功能 JFreeChart作为一款开源的JAVA项目,专为图表开发而设计,支持丰富的图表类型,包括饼图、柱状图(含普通及堆栈柱状图)、线图、散点图、...
在本学习笔记中,我们将深入探讨如何使用 JFreeChart 来构建这些图表,特别是混合图和动态时序图。 首先,构建一个 JFreeChart 图表的基本步骤涉及以下三个主要部分: 1. **创建面板容器**:通常,我们可以继承 `...
在本文中,我们将深入探讨如何使用JFreeChart库在Java中创建简单的柱状图,以及如何扩展到3D效果。JFreeChart是一个流行的开源图表库,适用于多种图表类型,包括条形图、线形图、饼图等。通过学习本文,你将能够利用...
**JFreeChart学习笔记** JFreeChart是一款强大的Java图表库,它允许开发者在应用程序、Swing组件、Applet或Web应用中创建各种复杂的图表。这个开源项目提供了多种图表类型,如饼图、柱状图、线图、散点图、甘特图等...
3. **文本文件**:“新建 文本文档.txt”和“新建 文本文档 (2).txt”可能包含了开发过程中的一些笔记、代码片段或者是关于如何配置和使用 JFreeChart 的提示。 **三、应用实践** 1. **饼图**:饼图常用于表示各...
通过阅读这些笔记,可以更快地掌握JFreeChart的使用技巧。 9. **社区支持** JFreeChart有一个活跃的开发者社区,提供技术支持和更新。遇到问题时,可以在官方论坛或Stack Overflow上寻求帮助,通常会有经验丰富的...
这个资源包包含了使用JFreeChart生成图表的代码示例,以及作者的整理笔记,旨在帮助开发者更好地理解和应用JFreeChart。 首先,JFreeChart的核心功能是生成各种类型的图表,如: 1. **饼形图(Pie Chart)**:饼形...
这篇总结笔记将详细介绍JFreeChart的各个方面,帮助你理解和掌握如何使用这个库。 一、JFreeChart简介 JFreeChart是开源的Java库,它提供了一套丰富的API来生成高质量的图表。这些图表可以用于数据分析、报表生成...
《jFreeChart实例解析与应用》 在Java编程世界中,数据可视化是一个至关重要的环节,它能够帮助我们更好地理解和分析数据。jFreeChart作为一个强大的开源图表库,为Java开发者提供了丰富的图表类型和高度自定义的...
在本学习笔记中,我们将深入探讨Struts的核心特性、国际化、类型转换以及JFreeChart的使用。 一、Struts框架基础 Struts 1是一个经典的Web MVC框架,它为开发者提供了强大的请求处理、页面导航、业务逻辑组织等功能...
总之,"Java学习笔记"涵盖了从基础到进阶的众多Java主题,结合JFreeChart和iText这两个实用库,不仅提供了对Java编程语言的深入理解,还展示了其在数据可视化和文档生成方面的强大能力。对于任何希望提升Java技能的...
`笔记.txt` 文件可能包含了作者在开发过程中的一些笔记或教程,可能记录了如何配置和使用 `JFreeChartDemo` 的详细步骤。 通过运行 `JFreeChartDemo`,开发者可以了解如何使用 JFreeChart API 创建不同的图表,同时...