JFreeChart中画3D饼图

工作需要,需要一个饼图,贴出来供大家学习

特别说明,需要下面的包(如果没有,可发邮件E-mail:info@easydone.cn):
jfreechart-1.0.0-rc1.jar
jfreereport-0.8.7-2.jar
jcommon-1.0.0-rc1.jar
junit-3.8.1.jar
包含如下功能:
设定链接
指定图片的透明度
指定显示的饼图上圆形(false)还椭圆形(true)
显示百分比
设置图片背景色
设置图片标题属性(中文)

效果图如下:

PiePlot3d.jsp 代码如下
<%
/**
 * <p>Title: JFreeChart中画3D饼图</p>
 * <p>Description: 一个简单的3D饼图,数据为测试数据</p>
 * <p>Copyright: Copyright (c) 2006 www.easydone.com.cn</p>
 * <p>Company: 北京聚能易成科技有限公司</p>
 * @Created on 2006-4-15 23:43
 * @authory dirboy
 * @version 1.0
 */
%>
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="org.jfree.data.general.DefaultPieDataset"%>
<%@ page import="org.jfree.chart.*"%>
<%@ page import="org.jfree.chart.plot.*"%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.chart.labels.StandardPieItemLabelGenerator"%>
<%@ page import="org.jfree.chart.urls.StandardPieURLGenerator"%>
<%@ page import="org.jfree.chart.entity.StandardEntityCollection"%>
<%@ page import="java.io.*"%>
<%@ page import="java.awt.Font"%>
<%@ page import="org.jfree.chart.title.TextTitle"%>
<%@page import="java.awt.Color"%>
<%@page import="org.jfree.chart.labels.StandardPieItemLabelGenerator"%>

<%
 String title = "2005 搜索引擎市场占有率";//数据为测试数据
 
 DefaultPieDataset piedata = new DefaultPieDataset();
 
 //第一个参数为名称,第二个参数是double数
 piedata.setValue("Google",30);
 piedata.setValue("Baidu",40.3);
 piedata.setValue("sohu",19.6);
 piedata.setValue("msn",29.6);
 
 //3D饼图
 PiePlot3D plot = new PiePlot3D(piedata);
 
 //设定链接 ("link.jsp","section"));//section为参数,不填写则默认为category
 plot.setURLGenerator(new StandardPieURLGenerator("link.jsp","section"));
 
 //指定图片的透明度
 plot.setForegroundAlpha(0.5f);
 
 //指定显示的饼图上圆形(false)还椭圆形(true)
 plot.setCircular(false);
 
 //显示百分比
 plot.setLabelGenerator(new StandardPieItemLabelGenerator(StandardPieItemLabelGenerator.DEFAULT_TOOLTIP_FORMAT));
 plot.setLegendLabelGenerator(new StandardPieItemLabelGenerator("{0}: ({1}M, {2})"));
   
 JFreeChart chart = new JFreeChart("",JFreeChart.DEFAULT_TITLE_FONT, plot, true);
 //设置图片背景色
 chart.setBackgroundPaint(java.awt.Color.white);
 
 //设置图片标题属性
 Font font = new Font("黑体",Font.CENTER_BASELINE,20);
 TextTitle _title = new TextTitle(title);
 _title.setFont(font);
 chart.setTitle(_title);
 
 plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
 //把生成的图片放到临时目录
 StandardEntityCollection sec = new StandardEntityCollection();
 ChartRenderingInfo info = new ChartRenderingInfo(sec);
 
 //500是图片长度,300是图片高度,session 为HttpSession对象
 String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
 
 PrintWriter pw = new PrintWriter(out);
 ChartUtilities.writeImageMap(pw, "map0", info, false);
 String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename; 

%>
<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>

</body>
</html>

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值