jsp页面中
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="org.jfree.data.general.DefaultPieDataset"%>
<%@ page import="org.jfree.chart.JFreeChart"%>
<%@ page import="org.jfree.chart.plot.PiePlot"%>
<%@ page import="org.jfree.chart.ChartRenderingInfo"%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.chart.urls.StandardPieURLGenerator"%>
<%@ page import="org.jfree.chart.entity.StandardEntityCollection"%>
<%@ page import="org.jfree.chart.encoders.SunPNGEncoderAdapter"%>
<%
?DefaultPieDataset data = new DefaultPieDataset();
?data.setValue("六月", 500);
?data.setValue("七月", 580);
?data.setValue("八月", 828);
?PiePlot plot = new PiePlot(data);
?JFreeChart chart = new JFreeChart("",
???JFreeChart.DEFAULT_TITLE_FONT, plot, true);
?chart.setBackgroundPaint(java.awt.Color.white); //可选,设置图片背景色
?chart.setTitle("Welcome to Jfreechart !"); //可选,设置图片标题
?ChartRenderingInfo info = new ChartRenderingInfo(
???new StandardEntityCollection());
?//500是图片长度,300是图片高度
?String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300,
???info, session);
?String graphURL = request.getContextPath()
???+ "/servlet/DisplayChart?filename=" + filename;
%>
<HTML>
?<HEAD>
??<TITLE>Welcome to Jfreechart !</TITLE>
?</HEAD>
?<BODY>
??<P ALIGN="CENTER">
???<img src="<%=graphURL%>" width=500 height=300 border=0
????usemap="#<%= filename %>">
??</P>
?</BODY>
</HTML>
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
?http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
?
?<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>/servlet/DisplayChart</url-pattern>
?</servlet-mapping>
?<servlet>
?
??<welcome-file-list>
??<welcome-file>index.jsp</welcome-file>
?</welcome-file-list>
</web-app>
?
转自:http://www.blogjava.net/liudecai/archive/2009/01/11/250847.html