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 ...
随机推荐
- 剑指offer 面试34题
面试34题: 题目:二叉树中和为某一值的路径 题:输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径. 解题代码 ...
- 电信、网通、联通等恶意DNS劫持跳广告页面的解决方法
中国电信.网通.联通ADSL用户必读:中国电信.网通.联通劫持dns(中国电信.网通.联通劫持ie浏览器)解决方案D... 宽带连接有 也能上网但是本地连接一直显示为受限制的解决方法 我的电脑一直显示 ...
- django admin基础
通过onetoonefiled扩展得到的不会在添加user是自动添加原因是onetoonefiled只是一个model 可以they are just Django models that happe ...
- 前端 JS&&DOM续
JS续 1.序列化 JSON.stringify(obj) 序列化 JSON.parse(str) 反序列化 2.转义 decodeURI( ) ...
- sublime text C++
几乎每一门编程语言都是从"Hello, world!"学起的, 刚学编程的时候感觉有点枯燥, 对它不够重视. 可是到后来慢慢发现, 几乎我学到的每一个知识点, 在最开始都是经过 h ...
- public,protected,privat区别
关于从基类继承来的方法和属性的保护: --class Pig:public Animal {...} C++不仅允许你对在类里定义的方法和属性实施访问控制,还允许你控制子类可以访问基类里的哪些方法和属 ...
- Django---media静态文件的配置&全局变量
media 静态文件配置 static 静态文件多用于存放用于渲染前端页面的相关数据,media用于存放客户上传或其他的文件 setting.py 中加入路径 MEDIA_ROOT = ( os.pa ...
- Kubernetes pod网络解析
在Kubernetes中,会为每一个pod分配一个IP地址,pod内的所有容器都共享这个pod的network namespace,彼此之间使用localhost通信. 那么pod内所有容器间的网络是 ...
- poj 3080 Blue Jeans【字符串处理+ 亮点是:字符串函数的使用】
题目:http://poj.org/problem?id=3080 Sample Input 3 2 GATACCAGATACCAGATACCAGATACCAGATACCAGATACCAGATACCA ...
- C++中容器的使用(一)
C++中有两种类型的容器:顺序容器和关联容器. 顺序容器主要有vector.list.deque等.其中vector表示一段连续的内存,基于数组实现,list表示非连续的内存,基于链表实现,deque ...