一.步骤:(发现另一位博主写的更详细: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. staticmethod

    python staticmethod 返回函数的静态方法. 该方法不强制要求传递参数,如下声明一个静态方法: class C(object): @staticmethod def f(arg1, a ...

  2. Android:日常学习笔记(8)———探究UI开发(5)

    Android:日常学习笔记(8)———探究UI开发(5) ListView控件的使用 ListView概述 A view that shows items in a vertically scrol ...

  3. Yii2 注册表单验证规则 手机注册时候使用短信验证码

    public function rules() { return [ ['username', 'filter', 'filter' => 'trim'], ['username', 'requ ...

  4. Hibernate多对多关联

    多对多关联: 示例:Teacher和Student,一个Teacher可以教很多student,一个Student也可以被很多teacher教   多对多单向关联 Teacher知道自己教了哪些学生, ...

  5. 06_Hadoop配置伪分布式模式详解

    查看IP地址,设为手动模式: 配置hadoop用户sudo权限 su切换到root身份,配置vim /etc/sudoers文件,加入 hadoop ALL=(root)NOPASSWD:ALL    ...

  6. 【Tech】mac下svn和scp使用笔记

    1.命令行从svn下载代码 mac本身自带svn,所以使用非常简单,在本地创建代码存放的文件夹,然后cd到该文件夹下,运行: svn checkout svn://ip地址/文件路径 . 然后出现要求 ...

  7. mybatis collection 一对多关联查询,单边分页的问题总结!

    若想直接通过sql实现多级关联查询表结构得有2 个必不可少的字段:id ,parentId,levelId id:主键id, parentId:父id levelId:表示第几级(表本身关联查询的时候 ...

  8. Go 内置库 IO interface

    基本的 IO 接口 io 包为 I/O 原语提供了基本的接口.它主要包装了这些原语的已有实现. 由于这些接口和原语以不同的实现包装了低级操作,因此除非另行通知,否则客户端不应假定它们对于并行执行是安全 ...

  9. mongodb 中的Multikey Index Bounds解释$elemMatch

    首先说一下 $elemMatch的用法: { _id: 1, results: [ 82, 85, 88 ] } { _id: 2, results: [ 75, 88, 89 ] } $elemMa ...

  10. 利用CXF框架开发webservice

    开发服务端代码 1. web.xml文件中添加cxf的servlet 2. 定义接口 @WebService(targetNamespace="http://UserInfo.ws.com& ...