<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    JAVA歷程
    希望我的這個博客能給那些想在java的海洋中拼搏的人有所幫助。謝謝光臨!
    posts - 8,  comments - 6,  trackbacks - 0

    采用工具類ChartUtil和DisplayChart(jfreechart的servlet)輸出

    將javabean里的生成圖片的方法寫的一個工具類ChartUtil里面。

    1 .添加工具類ChartUtil
    public class ChartUtil {
    // 產生時間序列圖,返回圖片名稱

    代碼
    1. public  static String generatePieChart(DefaultPieDataset dataset,String title,int width,int height,HttpSession session, PrintWriter pw) {       
    2.      
    3. String filename = null;       
    4.  try {       
    5.  if (session != null)       
    6.  {       
    7. ChartDeleter deleter = (ChartDeleter)session.getAttribute("JFreeChart_Deleter");       
    8.  session.removeAttribute("JFreeChart_Deleter");       
    9.  session.setAttribute("JFreeChart_Deleter", deleter);       
    10. }       
    11. JFreeChart chart = ChartFactory.createPieChart3D(       
    12. title,  // chart title       
    13. dataset, // data       
    14. true,  // include legend       
    15. true,       
    16. false );       
    17. //  Write the chart image to the temporary directory       
    18. ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());       
    19. //If the last parameter is null, the chart is a "one time"-chart and will be deleted after the first serving.       
    20. //If the last parameter is a session object, the chart remains until session time out.       
    21. filename = ServletUtilities.saveChartAsPNG(chart, width, height, info, session);       
    22. //  Write the image map to the PrintWriter       
    23.  ChartUtilities.writeImageMap(pw, filename, info,true);       
    24.  pw.flush();       
    25. catch (Exception e) {       
    26.  System.out.println("Exception - " + e.toString());       
    27.  e.printStackTrace(System.out);       
    28.  filename = "picture_error.png"; }       
    29. return filename;       
    30. }       
    31. }      

     

    2、在action里統計數據,設置好數據集dataset。傳到頁面

    3、 在頁面里取出

    代碼
    1. DefaultPieDataset piedataset=(DefaultPieDataset)request.getAttribute("piedataset");    
    2. String p = ChartUtil.generatePieChart(piedataset," 項目收支線圖",500,300,null, new PrintWriter(out));       
    3. String p1 = request.getContextPath() + "/servlet/DisplayChart?filename=" + p;   
    4.   
    5. <td><img src="<%= p1 %>" width=500 height=300 border=0 usemap="#<%= p %>"></td>     

     

    4、在web.xml中添加

    代碼
    1. <servlet>     
    2.   <servlet-name>DisplayChart</servlet-name>     
    3.   <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>     
    4. </servlet>     
    5. <servlet-mapping>     
    6.     <servlet-name>DisplayChart</servlet-name>     
    7.     <url-pattern>/servlet/DisplayChart</url-pattern>     
    8. </servlet-mapping>  
    posted on 2009-10-14 14:16 I LOVE JAVA 閱讀(614) 評論(0)  編輯  收藏 所屬分類: java基礎知識java高端技術

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(1)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费观看无遮挡www的视频| 91精品全国免费观看含羞草| 一个人免费观看在线视频www| 久久精品亚洲一区二区| 久久免费99精品国产自在现线| 国产乱弄免费视频| 激情小说亚洲图片| 亚洲AV日韩精品一区二区三区| 亚洲Av无码国产一区二区| 啦啦啦在线免费视频| 国产精品自拍亚洲| vvvv99日韩精品亚洲| 成人午夜免费视频| 亚洲精品亚洲人成人网| 在线观看免费播放av片| 亚洲高清资源在线观看| 黄色片在线免费观看| 亚洲成a人片在线不卡一二三区| 日韩高清在线免费观看| 一区免费在线观看| 亚洲精品无码乱码成人| 亚欧日韩毛片在线看免费网站| 亚洲精品午夜在线观看| 好大好深好猛好爽视频免费| 亚洲AV香蕉一区区二区三区| 亚洲av区一区二区三| 久久狠狠躁免费观看2020| 亚洲精品午夜在线观看| 国产精品视频免费一区二区三区| 日韩大片免费观看视频播放| 中文亚洲AV片在线观看不卡| 日本免费大黄在线观看| 亚洲乱妇熟女爽到高潮的片| 免费在线观看a级毛片| 国产拍拍拍无码视频免费| 亚洲人成影院在线高清| 亚洲国产成人精品不卡青青草原| 亚洲一区二区三区免费| 亚洲最大成人网色| 久久久久久国产精品免费无码| 亚洲国产第一页www|