Java 报表之JFreeChart(第二讲)
1、利用 JFreeChart 创建按颜色分类的水果销售报表
package com.wcy.chart.bar; import javax.servlet.http.HttpSession; import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities; public class BarChart3 { public static String genBarChart(HttpSession session)throws Exception{
double[][] data = new double[][]{{1320},{720},{830},{400}};
String[] rowKeys = {"苹果","香蕉","橘子","梨子"};
String[] columnKeys = {"深圳"};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys,data);
JFreeChart chart = ChartFactory.createBarChart3D("水果销售统计图", "水果", "销售",
dataset, PlotOrientation.VERTICAL, true, true, true);
String fileName = ServletUtilities.saveChartAsPNG(chart, 700, 500, session);
return fileName;
}
}
<%@page import="com.wcy.chart.bar.BarChart3"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String fileName = BarChart3.genBarChart(session);
%>
<img alt="" src="DisplayChart?filename=<%=fileName %>" width="700" height="500">
</body>
</html>
2、利用 JFreeChart 创建按颜色分类并且按地区分类水果销售报表
package com.wcy.chart.bar; import javax.servlet.http.HttpSession; import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities; public class BarChart4 { public static String genBarChart(HttpSession session)throws Exception{
double[][] data = new double[][]{{1390,690,542,630},{529,650,1200,690},{780,450,1300,1120},{890,640,750,500}};
String[] rowKeys = {"苹果","香蕉","橘子","梨子"};
String[] columnKeys = {"上海","北京","贵州","广州"};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys,columnKeys,data);
JFreeChart chart = ChartFactory.createBarChart3D("水果销售统计图", "水果", "销售", dataset, PlotOrientation.VERTICAL, true, true, true);
String fileName = ServletUtilities.saveChartAsPNG(chart, 700, 500, session);
return fileName;
}
}
<%@page import="com.wcy.chart.bar.BarChart4"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String fileName = BarChart4.genBarChart(session);
%>
<img alt="" src="DisplayChart?filename=<%=fileName %>" width="700" height="500" border="0">
</body>
</html>
3、利用 JFreeChart 创建自定义 3D 柱状报表
package com.wcy.chart.bar; import java.awt.Color; import javax.servlet.http.HttpSession; import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.ui.TextAnchor; public class BarChart5 { public static String genBarChart(HttpSession session)throws Exception{
double[][] data = new double[][]{{1299,459,980,470},{590,564,300,1130},{1200,357,910,380},{509,1300,650,810}};
String[] rowKeys = {"苹果","香蕉","橘子","梨子"};
String[] columnKeys = {"上海","北京","厦门","贵州"};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys,data);
JFreeChart chart = ChartFactory.createBarChart3D("水果销售统计图", "水果", "销售", dataset, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = chart.getCategoryPlot(); // 设置网格背景颜色
plot.setBackgroundPaint(Color.WHITE);
// 设置网格竖线颜色
plot.setDomainGridlinePaint(Color.pink);
// 设置网格横线颜色
plot.setRangeGridlinePaint(Color.pink); // 显示每个柱的数值,并修改该数值的字体属性
BarRenderer3D renderer=new BarRenderer3D();
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true); renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
renderer.setItemLabelAnchorOffset(10D); // 设置平行柱的之间距离
renderer.setItemMargin(0.4); plot.setRenderer(renderer); String fileName = ServletUtilities.saveChartAsPNG(chart, 700, 500, session);
return fileName;
}
}
<%@page import="com.wcy.chart.bar.BarChart5"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String fileName = BarChart5.genBarChart(session);
%>
<img alt="" src="DisplayChart?filename=<%=fileName %>" width="700" height="500" border="0">
</body>
</html>
声明:此程序代码本人只是用于学习总结,非原创,如有侵权,联系本人。
Java 报表之JFreeChart(第二讲)的更多相关文章
- Java 报表之JFreeChart(第一讲)
1.利用 JFreeChart 创建垂直柱状报表 package com.wcy.chart.bar; import javax.servlet.http.HttpSession; import or ...
- Java报表之JFreeChart
一.JFreeChart简介 JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications,servlets以及JSP等使用所设计. JFre ...
- 深入Java核心 Java内存分配原理精讲
深入Java核心 Java内存分配原理精讲 栈.堆.常量池虽同属Java内存分配时操作的区域,但其适用范围和功用却大不相同.本文将深入Java核心,详细讲解Java内存分配方面的知识. Java内存分 ...
- 购物商城学习--第二讲(maven工程介绍)
接下来第二讲介绍整体工程如何使用maven搭建的. 使用maven管理工程的好处: jar包的管理: 工程之间的依赖管理: 自动打包 maven常见打包方式:jar.war和pom三种.jar工程,是 ...
- WebApp 安全风险与防护课堂(第二讲)开课了!
本文由葡萄城技术团队于原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 在昨天的公开课中,由于参与的小伙伴们积极性和热情非常高,我们的讲师Carl ...
- POI教程之第二讲:创建一个时间格式的单元格,处理不同内容格式的单元格,遍历工作簿的行和列并获取单元格内容,文本提取
第二讲 1.创建一个时间格式的单元格 Workbook wb=new HSSFWorkbook(); // 定义一个新的工作簿 Sheet sheet=wb.createSheet("第一个 ...
- Stanford机器学习---第二讲. 多变量线性回归 Linear Regression with multiple variable
原文:http://blog.csdn.net/abcjennifer/article/details/7700772 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...
- 【军哥谈CI框架】之入门教程之第二讲:分析CI结构和CI是怎么工作的
[军哥谈CI框架]之入门教程之第二讲:分析CI结构和CI是怎么工作的 之入门教程之第二讲:分析CI结构和CI是如何工作的大家好!上一节,我们共同部署了一个CI网站,做到这一点非常简单,但是,亲们, ...
- 《ArcGIS Engine+C#实例开发教程》第二讲 菜单的添加及其实现
原文:<ArcGIS Engine+C#实例开发教程>第二讲 菜单的添加及其实现 摘要:在上一讲中,我们实现了应用程序基本框架,其中有个小错误,在此先跟大家说明下.在“属性”选项卡中,我们 ...
随机推荐
- HBase之show table
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import or ...
- iframe 根据加载内容调整高度
iframe标签代码 <iframe id="checkListFrame" name="checkListFrame" src="Ind ...
- EditText设置文字改变时的监听
textWatcher = new TextChangeWatcher(); etQuerryInfo.addTextChangedListener(textWatcher); /** * 文字改变类 ...
- Yii 添加Input时间插件
1.首先引入时间组件的JS文件,组件可以在网上下载到没有的可以到网上去下载 <script language="javascript" type="text/jav ...
- Implement strStr() [LeetCode]
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- 如何有效使用Project(2)——进度计划的执行与监控
继上次的的<编制进度计划.保存基准>继续讲解如何对计划进行执行和监控. 计划执行即:反馈实际进度.反馈工作消耗(本文只考虑工时,不考虑成本).提出计划变更请求.如果你的企业实施了专门的PM ...
- Rest接口测试,巧用firebug插件
两年前开始做软件测试,刚接触的是关于rest接口的测试.作为一个刚进职场的测试小菜鸟,当时对接口的理解并不是很充分,具体是怎么实现的也不清楚.在进行接口测试时,只是设置接口入参,调用接口,查看接口是否 ...
- 测试nfs和cifs
losetup /dev/loop1 file1.img losetup /dev/loop2 file2.img losetup /dev/loop3 file3.img mkfs -t ext4 ...
- 史上最全的RunLoop介绍
之前有人在后台给小编留言,说:小编啥时候给我们分享RunLoop的一些文章,工作以后特别需要这样的技术.这不,小编从网上找了一个介绍非常详细,清晰的文章,仅供参考. RunLoop 是 iOS 和 O ...
- AspectJ的基本使用
参考: https://my.oschina.net/itblog/blog/208067