JFreeChart - 简记
一.步骤:(发现另一位博主写的更详细:https://www.cnblogs.com/dmir/p/4976550.html)
- 创建数据集(准备数据)
- 根据数据集生成JFreeChart对象,并对其做相应的设置(标题,图例,x轴,Y轴,对象渲染等)
- 将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 - 简记的更多相关文章
- RangePartitioner 实现简记
摘要: 1.背景 2.rangeBounds 上边界数组源码走读 3.RangePartitioner的sketch 源码走读 4.determineBounds 源码走读 5.关于RangePart ...
- 【Java EE 学习 74 下】【数据采集系统第六天】【使用Jfreechart的统计图实现】【将JFreechart整合到项目中】
之前说了JFreechart的基本使用方法,包括生成饼图.柱状统计图和折线统计图的方法.现在需要将其整合到数据采集系统中根据调查结果生成三种不同的统计图. 一.统计模型的分析和设计 实现统计图显示的流 ...
- 【Java EE 学习 74 上】【数据采集系统第六天】【使用Jfreechart的统计图实现】【Jfreechart的基本使用方法】
之前已经实现了数据的采集,现在已经有了基本的数据,下一步就需要使用这些数据实现统计图的绘制了.这里使用Jfreechart实现这些统计图的绘制.首先看一下Jfreechart的基本用法,只有知道了它的 ...
- JFreeChart
花了四个小时给同学写的.还行吧,原来都没有用过到处找资料写的. package DrawLine; import org.jfree.chart.ChartFactory; import org.jf ...
- ZK 使用jfreeChart
前台: <?page title="Grid使用" contentType="text/html;charset=UTF-8"?> <zk x ...
- JFreechart在linux下不显示及中文乱码问题
一.使用JFreeChart建的报表,在window下能正常显示,但是放到linux下就报错,而且有时候会把tomcat挂掉, 原因是jfreechart的在linux系统中需要访问java awt库 ...
- JFreechart 在linux下不显示及中文乱码问题
一.使用JFreeChart建的报表,在window下能正常显示,但是放到linux下就报错,而且有时候会把tomcat挂掉, 原因是jfreechart的在linux系统中需要访问java awt库 ...
- Jfreechart初案例--饼图
1.action @Controller(value = "pieAction") @Scope("prototype") public class PieAc ...
- jfreechart 整合sturts2牛刀小试
一.增加的jar包 struts2-jfreechart-plugin-2.1.6.jar 在struts2的相应jar包中找 jcommon-1.0.23.jar ...
随机推荐
- javascript高级语法三
一.js的正则表达式 1.什么是正则表达式 正则表达式(regular expression)是一个描述字符模式的对象,ECMAScript的RegExp类表示正则表达式,而String和RegExp ...
- 当退出python时,是否释放全部内存
答案是no,循环引用其他对象或引用自全局命名空间的对象的模块,在python退出时并非完全释放 另外,也不会释放c库保留的内存部分
- 极速Node.js:来自LinkedIn的10个性能提升秘籍
from:http://faylai.iteye.com/blog/1293194 1.避免使用同步的方法 nodejs 是基于单线程.为了让单线程能够处理高并发的请求,我们尽量要避免让线程等待,阻塞 ...
- iOS WKWebView OC 与 JS 交互学习
我写WKWebView 想让 服务端相应 一个 方法但是不响应,根据 UIWebView 用 JSContext就能拿到响应的处理经验是不是服务端 也需要 对 WKwebView有兼容的一个写法??? ...
- java DateTimeUtil 日期工具类
package com.sicdt.library.core.utils; import java.sql.Timestamp; import java.text.DateFormat; import ...
- Java技术路线
1.计算机基础: 1.1数据机构基础: 主要学习: 1.向量,链表,栈,队列和堆,词典.熟悉 2.树,二叉搜索树.熟悉 3.图,有向图,无向图,基本概念 4.二叉搜索A,B,C类熟练,9大排序熟悉. ...
- 20145231第二周Java学习笔记
20145231 <Java程序设计>第2周学习总结 教材学习内容总结 本周的学习采用的依然是先看课本,再看视频,然后实践敲代码,最后根据学习笔记总结完成博客. 第三章:基础语法 知识点比 ...
- linux 查看各目录(文件夹)下文件大小
# 显示总大小(/下全部文件占用大小) du -sh /* | sort -nr # 显示各文件夹的大小(当前文件夹下各文件夹的大小) du --max-depth=1
- python进阶03
进程线程不管哪门语言都是一块可以被重视的方向,下面一起学习学习python中的进程,线程 1.进程线程区别 通俗解释:一个程序QQ的运行就是一个进程运行:QQ中打开多个页面互不影响可以同时操作的每个页 ...
- 进程【TLCL】
ps命令 ps x 加上 "x" 选项(注意没有开头的 "-" 字符),告诉 ps 命令,展示所有进程,不管它们由什么 终端(如果有的话)控制. 在 TTY 一 ...