日期:2014-05-17 浏览次数:20852 次
<%@ page language="java" import="java.util.*" pageEncoding="gbk" contentType="text/html; charset=gbk"%> <%@ page import="org.jfree.data.general.DefaultPieDataset" %> <%@ page import="org.jfree.chart.JFreeChart"%> <%@ page import="org.jfree.chart.ChartUtilities" %> <%@ 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"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <% //创建一个数据集对象 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.setTitle("JFreeChart测试"); //可选,设置图片标题 chart.setBackgroundPaint(java.awt.Color.white); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); //500是图片长度,300是图片高度 String filename =ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session); String url=request.getContextPath()+"/DisplayChart?filename="+filename; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>JfreeChart生成饼状图</title> </head> JfreeChart生成饼状图例子 <P ALIGN="CENTER"> <img src="<%=url%>" > </P> </body> </html>