工作需要,需要一个饼图,贴出来供大家学习
特别说明,需要下面的包(如果没有,可发邮件):
jfreechart-1.0.0-rc1.jar
jfreereport-0.8.7-2.jar
jcommon-1.0.0-rc1.jar
junit-3.8.1.jar
E-mail:[email protected]
barChart3D.jsp
<%
/**
*
Title: JFreeChart中画柱状图
Description: 一个简单的柱状图,数据为测试数据
Copyright: Copyright (c) 2006 www.easydone.com.cn
>Company: 北京聚能易成科技有限公司
<%
String queryTime = "2006-4-15 23:58";
DefaultCategoryDataset dataSet;
dataSet = new DefaultCategoryDataset();
dataSet.addValue(100,"北京","Gogole");
dataSet.addValue(200,"北京1","baidu");
dataSet.addValue(300,"北京2","sohu");
dataSet.addValue(400,"北京3","sina");
dataSet.addValue(500,"北京","yahoo");
JFreeChart chart=null;
chart = ChartFactory.createBarChart3D (
"11111111111111",
"X Info",
"Y Info",
dataSet,
PlotOrientation.VERTICAL,
true,
true,
false
);
chart.setTitle(queryTime+":测试数据");
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);
String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
//存储数据到本地硬盘
//ChartUtilities.saveChartAsJPEG(new File("c:/aa.jpeg"), 100, chart, 600, 600);
%>
<html>
<head>
<title>3D饼图</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="border">
<tr>
<td width="70" height="30">【<a href="<%=graphURL%>">下载</a>】</td>
</tr>
</table>
<br>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="border">
<tr>
<td><img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#map0"></td>
</tr>
</table>