一.步骤:(发现另一位博主写的更详细:https://www.cnblogs.com/dmir/p/4976550.html

  1. 创建数据集(准备数据)
  2. 根据数据集生成JFreeChart对象,并对其做相应的设置(标题,图例,x轴,Y轴,对象渲染等)
  3. 将JFreeChart对象输出到文件或者Servlet输出流等

1.饼状图

package com.jfreechart;

import java.awt.Font;
import java.io.File;
import java.io.IOException; import javax.swing.plaf.FontUIResource; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset; public class JFreeChartTestPie { public static void main(String[] args) throws IOException {
DefaultPieDataset ds = new DefaultPieDataset();
ds.setValue("IBM", 5000);
ds.setValue("ORACLE", 6000);
ds.setValue("JBOSS", 7000);
ds.setValue("用友", 8000); JFreeChart chart = ChartFactory.createPieChart3D("标题", ds, true, false, false); // 设定标题字体
chart.getTitle().setFont(new FontUIResource("宋体", Font.BOLD, 20));
// 提示条字体
chart.getLegend().setItemFont(new FontUIResource("宋体", Font.PLAIN, 15)); // 绘图区
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelFont(new FontUIResource("宋体", Font.ITALIC, 12));
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}({1}), {2}")); // 设置绘图区背景
// plot.setBackgroundImage(ImageIO.read(new File("D:/Hydrangeas.jpg"))); // 设置分离效果,3d不支持分离效果
plot.setExplodePercent("IBM", 0.1F);
plot.setExplodePercent("JBOSS", 0.1F); // 设置透明度
plot.setForegroundAlpha(0.7f); try {
ChartUtilities.saveChartAsJPEG(new File("D:/Piechart.jpg"), chart, 800, 500);
} catch (IOException e) {
e.printStackTrace();
}
} }

2.条形图

package com.jfreechart;

import java.awt.Font;
import java.io.File;
import java.io.IOException; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset; public class JFreeChartTestBar { public static void main(String[] args) {
DefaultCategoryDataset ds = new DefaultCategoryDataset();
ds.setValue(3400, "IBM", "一季度");
ds.setValue(3600, "ORACLE", "一季度");
ds.setValue(3100, "JBOSS", "一季度");
ds.setValue(2800, "用友", "一季度"); ds.setValue(3600, "IBM", "二季度");
ds.setValue(3800, "ORACLE", "二季度");
ds.setValue(4000, "JBOSS", "二季度");
ds.setValue(2900, "用友", "二季度"); ds.setValue(3400, "IBM", "三季度");
ds.setValue(3600, "ORACLE", "三季度");
ds.setValue(4000, "JBOSS", "三季度");
ds.setValue(2900, "用友", "三季度"); JFreeChart chart = ChartFactory.createBarChart3D("前三季度销量比较", "季度", "销量(单位:万台)", ds, PlotOrientation.VERTICAL, true, false, false); // 设定标题字体
chart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));
// 提示条字体
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 15)); // 绘图区
CategoryPlot plot = chart.getCategoryPlot();
plot.getDomainAxis().setLabelFont(new Font("宋体", Font.PLAIN, 15));
plot.getDomainAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 15)); plot.getRangeAxis().setLabelFont(new Font("宋体", Font.PLAIN, 15));
plot.getRangeAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 15)); try {
ChartUtilities.saveChartAsJPEG(new File("D:/Barchart.jpg"), chart, 800, 500);
} catch (IOException e) {
e.printStackTrace();
} } }

3.折线图

package com.jfreechart;

import java.awt.Font;
import java.io.File;
import java.io.IOException; import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset; public class JFreeChartTestLine { public static void main(String[] args) {
DefaultCategoryDataset ds = new DefaultCategoryDataset();
ds.setValue(3400, "IBM", "一季度");
ds.setValue(3600, "ORACLE", "一季度");
ds.setValue(3100, "JBOSS", "一季度");
ds.setValue(2800, "用友", "一季度"); ds.setValue(3600, "IBM", "二季度");
ds.setValue(3800, "ORACLE", "二季度");
ds.setValue(4000, "JBOSS", "二季度");
ds.setValue(2900, "用友", "二季度"); ds.setValue(3400, "IBM", "三季度");
ds.setValue(3600, "ORACLE", "三季度");
ds.setValue(4000, "JBOSS", "三季度");
ds.setValue(2900, "用友", "三季度"); JFreeChart chart = ChartFactory.createLineChart("前三季度销量比较", "季度", "销量(单位:万台)", ds, PlotOrientation.VERTICAL, true, false, false); // 设定标题字体
chart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));
// 提示条字体
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 15)); // 绘图区
CategoryPlot plot = chart.getCategoryPlot();
plot.getDomainAxis().setLabelFont(new Font("宋体", Font.PLAIN, 15));
plot.getDomainAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 15)); plot.getRangeAxis().setLabelFont(new Font("宋体", Font.PLAIN, 15));
plot.getRangeAxis().setTickLabelFont(new Font("宋体", Font.PLAIN, 15));
plot.getRangeAxis().setRangeWithMargins(2000, 5000);
try {
ChartUtilities.saveChartAsJPEG(new File("D:/Linechart.jpg"), chart, 800, 500);
} catch (IOException e) {
e.printStackTrace();
} } }
 

JFreeChart - 简记的更多相关文章

  1. RangePartitioner 实现简记

    摘要: 1.背景 2.rangeBounds 上边界数组源码走读 3.RangePartitioner的sketch 源码走读 4.determineBounds 源码走读 5.关于RangePart ...

  2. 【Java EE 学习 74 下】【数据采集系统第六天】【使用Jfreechart的统计图实现】【将JFreechart整合到项目中】

    之前说了JFreechart的基本使用方法,包括生成饼图.柱状统计图和折线统计图的方法.现在需要将其整合到数据采集系统中根据调查结果生成三种不同的统计图. 一.统计模型的分析和设计 实现统计图显示的流 ...

  3. 【Java EE 学习 74 上】【数据采集系统第六天】【使用Jfreechart的统计图实现】【Jfreechart的基本使用方法】

    之前已经实现了数据的采集,现在已经有了基本的数据,下一步就需要使用这些数据实现统计图的绘制了.这里使用Jfreechart实现这些统计图的绘制.首先看一下Jfreechart的基本用法,只有知道了它的 ...

  4. JFreeChart

    花了四个小时给同学写的.还行吧,原来都没有用过到处找资料写的. package DrawLine; import org.jfree.chart.ChartFactory; import org.jf ...

  5. ZK 使用jfreeChart

    前台: <?page title="Grid使用" contentType="text/html;charset=UTF-8"?> <zk x ...

  6. JFreechart在linux下不显示及中文乱码问题

    一.使用JFreeChart建的报表,在window下能正常显示,但是放到linux下就报错,而且有时候会把tomcat挂掉, 原因是jfreechart的在linux系统中需要访问java awt库 ...

  7. JFreechart 在linux下不显示及中文乱码问题

    一.使用JFreeChart建的报表,在window下能正常显示,但是放到linux下就报错,而且有时候会把tomcat挂掉, 原因是jfreechart的在linux系统中需要访问java awt库 ...

  8. Jfreechart初案例--饼图

    1.action @Controller(value = "pieAction") @Scope("prototype") public class PieAc ...

  9. jfreechart 整合sturts2牛刀小试

    一.增加的jar包 struts2-jfreechart-plugin-2.1.6.jar      在struts2的相应jar包中找 jcommon-1.0.23.jar              ...

随机推荐

  1. 流量监控系统---storm集群配置

    1.集群部署的基本流程 集群部署的流程:下载安装包.解压安装包.修改配置文件.分发安装包.启动集群 注意: 所有的集群上都需要配置hosts vi  /etc/hosts 192.168.223.20 ...

  2. iOS 系统认知 debug distribution release 和 #ifdef DEBUG

    debug:调试模式 有调试信息 线下 release: 无调试信息 经过了编译优化 发布 给用户使用的 线上模式  一般 工程项目 都是自带 上述两种配置结构 还有出现 distribution: ...

  3. jquery的autocomplete在firefox下不支持中文输入法的bug

    Query.Autocomplete 是jquery的流行插件,能够很好的实现输入框的自动完成(autocomplete).建议提示(input suggest)功能,支持ajax数据加载. 但唯一遗 ...

  4. 每天一个Linux命令(54)chkconfig命令

        chkconfig命令检查.设置系统的各种服务.     (1)用法:     用法:  chkconfig  [必要参数]  [服务]     (2)功能:     功能:  chkconf ...

  5. 40个你可能不知道的Python的特点和技巧

    1.拆箱 >>> a, b, c = 1, 2, 3 >>> a, b, c (1, 2, 3) >>> a, b, c = [1, 2, 3] ...

  6. 前端之CSS样式

    一.CSS 1.什么是CSS 层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的 ...

  7. MongoDB 使用Limit和Skip完成分页 和游标(二)

    //$slice操作符返回文档中指定数组的内部值 //查询出Jim书架中第2~4本书 db.persons.find({name:"jim"},{books:{"$sli ...

  8. get_called_class--后期静态绑定("Late Static Binding")类的名称

    get_called_class--后期静态绑定("Late Static Binding")类的名称 string get_called_class ( void ) 获取静态方 ...

  9. PHP 面向对象及Mediawiki 框架分析(二)

    mediaHandler可以理解为处理media文件的 /includes/filerepo/file/File.php /** * Get a MediaHandler instance for t ...

  10. React Native的生命周期解析

    在React Native中使用组件来封装界面模块时,整个界面就是一个大的组件,开发过程就是不断优化和拆分界面组件.构造整个组件树的过程. 上张图涵盖了一个组件从创建.运行到销毁的整个过程.大家可以看 ...