jfreechart动态显示投票结果

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="org.jfree.chart.JFreeChart,org.jfree.data.general.DefaultPieDataset,org.jfree.chart.ChartFactory,
,org.jfree.chart.servlet.ServletUtilities;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
 
   
    <title>My JSP 'jfreeChart.jsp' starting page</title>
   
 

  </head>
 
  <body>
 <%
  //jfreeChart.jsp为显示投票结果页面,具体项目中
//有一张vote表,其中有 votename,votecount,可以在用户按下投票按钮后,或查看结果时
//将请求发送到struts2等servlet中,这样在servlet中可以写 select votecount from vote

//将返回一个得票的数组,用一个int []votecount 来保存,并request.setAttribute("votecountarray",votecount)
//并配置跳转到jfreeChart.jsp页面中,这样在jfreeChart.jsp中可以通过迭代标签或request.getAttribute("votecountarray")

//来得到整形数组,这样可将“dpd.setValue”里的第二个参数动态的设置为每个投票项的投票数目,这样就可以动态创建投票的
//结果了.
 
 DefaultPieDataset dpd=new DefaultPieDataset();
 
 
 dpd.setValue("seller", 25);
 dpd.setValue("pineer", 40);
 dpd.setValue("backer", 10);
 dpd.setValue("orgnizeer", 25);
   JFreeChart chart=ChartFactory.createPieChart3D("the employee of a company", dpd, true, true, true);
 
 String fileName=ServletUtilities.saveChartAsJPEG(chart,800,600,session);
 
 String url=request.getContextPath()+"/DisplayChart?filename="+fileName;
 
  %>
 
         
 
 
 <img src="<%=url%>" width="500" height="300">
 
 
 
 
 
 
 
 
 
 
 
 
 
  </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值