廉颇老矣,尚能饭否

java:从技术到管理

常用链接

统计

最新评论

jfreechart应用_例题_生成饼状图(展示,生成文件,WEB项目)_可以直接运行

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>



柳德才
13691193654
18942949207
QQ:422157370
liudecai_zan@126.com
湖北-武汉-江夏-庙山

posted on 2009-01-11 11:38 liudecai_zan@126.com 阅读(1246) 评论(0)  编辑  收藏 所属分类: JFreeChart


只有注册用户登录后才能发表评论。


网站导航: