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>

發佈了53 篇原創文章 · 獲贊 1 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章