一.步骤:(发现另一位博主写的更详细: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. 基于 普通及Lambda方式实现策略模式

    什么是策略模式 策略模式代表了解决一类算法的通用解决方案,你可以在运行时选择使用哪种方案.比如如何使用不同的条件(比如苹果的重量,或者颜色 )来筛选库存中的苹果.你可以将这一模式应用到更广泛的领域 , ...

  2. MySQL数据库(4)_MySQL数据库外键约束、表查询

    一.外键约束 创建外键 --- 每一个班主任会对应多个学生 , 而每个学生只能对应一个班主任 ----主表 CREATE TABLE ClassCharger( id TINYINT PRIMARY ...

  3. Python进阶(3)_进程与线程中的lock(线程中互斥锁、递归锁、信号量、Event对象、队列queue)

    1.同步锁 (Lock) 当全局资源(counter)被抢占的情况,问题产生的原因就是没有控制多个线程对同一资源的访问,对数据造成破坏,使得线程运行的结果不可预期.这种现象称为“线程不安全”.在开发过 ...

  4. SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传

    SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传 配置CKEDITOR 精简文件 解压之后可以看到ckeditor/lang下面有很多语言的js,如果不需要那么多种语言的,可 ...

  5. HTML系列(2)基本的HTML标签(一)

        本节介绍基本的HTML标签的使用实例.     (1)h标签: <!DOCTYPE html> <html> <head> <title>示例2 ...

  6. 每天一个Linux命令(41)iostat命令

        iostat是I/O statistics(输入/输出统计)的缩写,对系统的磁盘操作活动进行监视.它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况.     (1)用法:     ...

  7. MyBatis SQL 生成方法 增删改查

    此类根据JAVA实体BEAN生成MYBATIS的接口SQL(mapper) package com.sicdt.sicsign.bill.service.hessian; import java.la ...

  8. curl操作封装

    <?php /** * Class Curl curl简单封装 get post */ class Curl { /** * @brief get请求 * @param $url 请求的url ...

  9. Java zip 压缩 文件夹删除,移动,重命名,复制

    FileUtil.java import java.io.*; import java.util.List; import java.util.zip.ZipEntry; import java.ut ...

  10. web框架详解之三Modal

    一.Modal操作之创建表,添加数据 1. 配置Django中settings的设置连接mysql数据库,然后在mysql数据库中创建库 2. 在models中创建表.继承Model 3. 在sett ...