JFreeChart画图+jsp页面显示实现统计图
1 开发环境:
1、eclipse(可替换)
2、jfreechart-1.0.19
2 说明:
(1) source目录:为 jfreechart的源码目录;不会的主要看这里。因为他的文档是收费的。
(2) lib目录:为包目录,我们需要关注的包为 jfreechart-1.0.10.jar、 gnujaxp.jar和 jcommon-1.0.13.jar这三个包;
(3)根目录下的 jfreechart-1.0.10-demo.jar是例子程序,大家双击后可看到其中有很多例子的运行结果。
3 JavaWeb开发流程
3.1 导入jar包
将jfreechart-1.0.19/lib下面所有jar包导入到“/WEB-INF/lib”目录下
3.2 修改配置文件
在 web.xml文件中增加如下配置,尽量配置在其他优先级不高的servlet配置前面:
<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>
org.jfree.chart.servlet.DisplayChart <!--这个固定不变-->
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/DisplayChart</url-pattern>
</servlet-mapping>
3.3 编写jsp文件
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%> <%@ page import="org.jfree.data.general.DefaultPieDataset" %>
<%@ page import="org.jfree.chart.ChartFactory" %>
<%@ page import="org.jfree.chart.JFreeChart" %>
<%@ page import="org.jfree.chart.servlet.*" %>
<%@ page import="org.jfree.chart.StandardChartTheme" %>
<%@ page import="java.awt.Font" %>
<%@page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.chart.plot.PlotOrientation"%>
<%@ page import="org.jfree.data.category.DefaultCategoryDataset"%> <!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>数据分析</title>
</head>
<body>
<!-- 饼状图 -->
<%
DefaultPieDataset dpd = new DefaultPieDataset();
dpd.setValue("管理人员", );
dpd.setValue("市场人员", );
dpd.setValue("开发人员", );
dpd.setValue("其他人员", ); //这一段是防止乱码使用的
StandardChartTheme standardChartTheme=new StandardChartTheme("CN"); //创建主题样式
standardChartTheme.setExtraLargeFont(new Font("隶书",Font.BOLD,)); //设置标题字体
standardChartTheme.setRegularFont(new Font("宋书",Font.PLAIN,)); //设置图例的字体
standardChartTheme.setLargeFont(new Font("宋书",Font.PLAIN,)); //设置轴向的字体
ChartFactory.setChartTheme(standardChartTheme); //应用主题样式 JFreeChart chart = ChartFactory.createPieChart("某公司组织结构图",dpd, true, false, false);
String fileName = ServletUtilities.saveChartAsPNG(chart,,,session);
//ServletUtilities是面向web开发的工具类,返回一个字符串文件名,文件名自动生成,生成好的图片会自动放在服务器(tomcat)的临时文件下(temp) String url = request.getContextPath() + "/DisplayChart?filename=" + fileName;
//根据文件名去临时目录下寻找该图片,这里的/DisplayChart路径要与配置文件里用户自定义的<url-pattern>一致
%>
<img src="<%= url %>" width="" height=""> <!-- 柱状图 -->
<%
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(0.2, "广州", "猪肉");
dataset.addValue(0.4, "广州", "牛肉");
dataset.addValue(0.1, "广州", "鸡肉");
dataset.addValue(0.1, "广州", "鱼肉");
// 创建主题样式
StandardChartTheme standardChartTheme1 = new StandardChartTheme("CN");
// 设置标题字体
standardChartTheme1.setExtraLargeFont(new Font("隶书", Font.BOLD, ));
// 设置图例的字体
standardChartTheme1.setRegularFont(new Font("宋书", Font.PLAIN, ));
// 设置轴向的字体
standardChartTheme1.setLargeFont(new Font("宋书", Font.PLAIN, ));
// 应用主题样式
ChartFactory.setChartTheme(standardChartTheme1); JFreeChart chart1 = ChartFactory.createBarChart3D("肉类销量统计图",
"肉类",
"销量百分比(%)",
dataset,
PlotOrientation.VERTICAL,
false,
false,
false);
String filename = ServletUtilities.saveChartAsPNG(chart1, , , null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename; System.out.println(graphURL + "\n"+ filename);
%>
<img src="<%= graphURL %>"width= height= border= usemap="#<%= filename %>"> </body>
</html>
4 效果图

附jar下载地址:http://www.java2s.com/Code/Jar/CatalogJar.htm
JFreeChart画图+jsp页面显示实现统计图的更多相关文章
- jfreechart 在jsp页面显示所画的图片(resin服务器的servelet配置是关键)(图片只过内存)
用的web服务器是resin服务器,在配置web.xml时需要注意,其实resin服务器的web.xml服务器配置和tomcat服务器的配置很像, 1. 我第一次按照自己的想法,想当然的在resin- ...
- 转:jsp页面显示中文乱码解决方案
jsp页面显示中文乱码: jsp页面的编码方式有两个地方需要设置: <%@ page language="java" import="java.util.*&quo ...
- JSP 页面显示sql中数据。el
存储数据库字段. package Bean; /** * Created by Administrator on 2017/5/24. */ public class info { private S ...
- 如何解决JSP页面显示乱码问题
一.JSP页面显示乱码 下面的显示JSP页面(display.jsp)就出现乱码: <html> <head> <title>JSP的中文处理</title& ...
- 通用分页jsp页面显示
注:本章内容都是在上一篇文章 通用分页后台显示:https://www.cnblogs.com/ly-0919/p/11058942.html 的基础上进行改进,所以有许多的类都在上一篇, 带来不便 ...
- jsp页面显示问题
一.在jsp页面的表格中,如果有表格中的某一个元素 内容太长,需要截取显示,方法如下: <%@ taglib prefix="fn" uri="http://jav ...
- JSP页面显示乱码
下面的显示页面(display.jsp)就出现乱码: <html> <head> <title>JSP的中文处理</title> <meta ht ...
- Java从服务器上获取时间,动态在jsp页面显示
Java获取服务器时间,动态显示到jsp页面,大家都是到Java只能获取一次,到页面的时间是静态的,不过通过js和Java的合作,巧妙地实现此功能 本人是给电视做系统,客户要求页面能显示时间,因为电视 ...
- Jsp页面显示时间:<fmt>标签问题
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%> <%@ taglib ...
随机推荐
- OsharpNS轻量级.net core快速开发框架简明入门教程-基于Osharp实现自己的业务功能
OsharpNS轻量级.net core快速开发框架简明入门教程 教程目录 从零开始启动Osharp 1.1. 使用OsharpNS项目模板创建项目 1.2. 配置数据库连接串并启动项目 1.3. O ...
- Python中collections模块
目录 Python中collections模块 Counter defaultdict OrderedDict namedtuple deque ChainMap Python中collections ...
- 带你了解SDL
SDL(英语:Simple DirectMedia Layer)是一套开放源代码的跨平台多媒体开发库,使用C语言写成.SDL提供了数种控制图像.声音.输出入的函数,让开发者只要用相同或是相似的代码就可 ...
- 【Python3爬虫】最新的模拟登录新浪微博教程
一.写在前面 首先呢,由于之前重装系统,又要重新配置环境,然后还有一些别的事,导致我一直没有写爬虫了,不过现在又可以继续写了. 然后我这次说的模拟登录新浪微博呢,不是使用Selenium模拟浏览器操作 ...
- JS 各种宽高
1.window的各种宽高 outerWidth.innerWidth.outerHeight.innerHeight outerHeight 获取浏览器窗口外部的高度(单位:像素).表示整个浏览 ...
- Windows 2012安装odoo12
- iOS----------时间戳与NSDate
1:时间戳转NSDate NSString *timeStamp =@"1545965436"; NSDate *date = [NSDate dateWithTimeInterv ...
- python3 字符编码与转码的理解
额...上通识课讲到了NLP12条,感觉讲的挺好的,照着抄一条先... 1,没有两个人是一样的 没有两个人的人生经验会完全一样,所以没有两个人的信念,价值和规条系统会是一样. 因此没有两个人对同一件事 ...
- vue 使用 supermap iclient-classic
1. 2.在组件中: import "@supermap/iclient-classic/libs/SuperMap-8.1.1-16520"; import { MapVLaye ...
- eShopOnContainers 知多少[1]:总体概览
引言 在微服务大行其道的今天,Java阵营的Spring Boot.Spring Cloud.Dubbo微服务框架可谓是风水水起,也不得不感慨Java的生态圈的火爆.反观国内.NET阵营,微服务却不愠 ...