waysun一路陽光

          不輕易服輸,不輕言放棄.--心是夢的舞臺(tái),心有多大,舞臺(tái)有多大。踏踏實(shí)實(shí)做事,認(rèn)認(rèn)真真做人。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
            167 隨筆 :: 1 文章 :: 64 評(píng)論 :: 0 Trackbacks
          因?yàn)槲宜诘捻?xiàng)目需要用到動(dòng)態(tài)生成顯示圖片,于是研究了一點(diǎn),先把源代碼以及完整的例子貼出來。
          (1)畫柱狀圖
          JAVA源代碼:

          /**
          *@author qingbao-gao
          *<p>Blog:http://www.cnweblog.com/nm1504</p>
          *<p>E-mail:yyk1504@163.com</p>
          *<p>創(chuàng)建時(shí)間:2008-1-3</p>
          *<p>Copyright: XXxxxXX (c)2008-1-3</p>
          */
          package com.mfsoft.net.jfreemap;

          import org.jfree.chart.ChartFactory;
          import org.jfree.chart.JFreeChart;
          import org.jfree.chart.plot.PlotOrientation;
          import org.jfree.data.category.DefaultCategoryDataset;

          import java.awt.Color;
          import org.jfree.chart.renderer.category.BarRenderer3D;
          import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
          import org.jfree.chart.axis.CategoryAxis;
          import org.jfree.chart.plot.CategoryPlot;

          import com.mfsoft.credit.modelmang.operation.EvalItemDataOperation;
          import com.mfsoft.credit.modelmang.operation.ModelDataTypeOperation;
          import com.mfsoft.net.pre.MoveWeightAverage;
          import com.mfsoft.net.pre.TimeSeriesForecast;

          public class DisplayMap
          {
           public DisplayMap()
           {
            
           }
           /**
            * <P>獲得圖形</P>
            * @param test           數(shù)據(jù)存儲(chǔ)數(shù)組
            * @param polyLineResult 柱狀圖要顯示的柱形
            * @param simuResult     柱狀圖要顯示的柱形
            * @param moveResult     柱狀圖要顯示的柱形
            * @param timeResult     柱狀圖要顯示的柱形
            * @author qingbao-gao
            * <p>Date:2008-01-03 PM 2:21</p>
            * @return               JFreeChart形式的對(duì)象供調(diào)用
            */

           public static JFreeChart displayResult(double[][]test,int polyLineResult,int simuResult,int moveResult,int timeResult)
           {
            int length=test.length;
              DefaultCategoryDataset dataset    = new DefaultCategoryDataset();
              //double [][]test=mdt.getMonthData("200609","200708","1100000000023","R");
              /*
                double[][]test=new double[][]{
                  {200606 ,63534},
                  {200607 ,64624},
                  {200608 ,64947},
                  {200609 ,64996},
                  {200610 ,65201},
                  {200611 ,65318},
                  {200612 ,65800},
                  {200701 ,66126},
                  {200702 ,66238},
                  {200703 ,66553},
                  {200704 ,66790},
                  {200705 ,67125},
                  {200706 ,67461},
                  {200707 ,67833},
                  {200708 ,68064},
                  {200709 ,68329},
                   };*/
                 //int taps=4;
                  for(int i=0;i<test.length-1;i++)
                  {
               dataset.addValue(test[i][1], "各月份數(shù)據(jù)", (String.valueOf(test[i][0])).substring(2, 7));
               //dataset.addValue(450, "各月份數(shù)據(jù)", "2月份");
               //dataset.addValue(550, "各月份數(shù)據(jù)", "3月份");
               //dataset.addValue(600, "各月份數(shù)據(jù)", "4月份");
                  }
                  EvalItemDataOperation ei=new EvalItemDataOperation();
                  String nextMonth=ei.getNextMonth(String.valueOf(test[length-1][0]));
                 dataset.addValue(simuResult, "神經(jīng)網(wǎng)絡(luò)預(yù)測", nextMonth);
                 dataset.addValue(timeResult, "時(shí)間序列預(yù)測", nextMonth);
                 dataset.addValue(moveResult, "移動(dòng)加權(quán)平均", nextMonth);
                 dataset.addValue(polyLineResult, "曲線擬合預(yù)測", nextMonth);
             
               JFreeChart chart = ChartFactory.createBarChart3D("時(shí)間序列柱狀圖-四種預(yù)測方法比較","預(yù)測顯示比較","實(shí)際客
          戶數(shù)與預(yù)測客戶數(shù)",dataset,PlotOrientation.VERTICAL,true,false,false);
              chart.setBackgroundPaint(Color.WHITE);
              CategoryPlot catePlot = chart.getCategoryPlot();

              CategoryAxis domainAxis = catePlot.getDomainAxis();
                    //domainAxis.setVerticalCategoryLabels(false);
              catePlot.setDomainAxis(domainAxis);

                    BarRenderer3D renderer = new BarRenderer3D();
                    renderer.setBaseOutlinePaint(Color.BLACK);

                    //設(shè)置每個(gè)地區(qū)所包含的平行柱的之間距離
                    renderer.setItemMargin(0.1);
                    //顯示每個(gè)柱的數(shù)值,并修改該數(shù)值的字體屬性
                    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
                    renderer.setItemLabelsVisible(true);
                    catePlot.setRenderer(renderer);
                    //設(shè)置柱的透明度
                    catePlot.setForegroundAlpha(0.8f);
                    return chart;
           }

          }

          下面是JSP里調(diào)用上面的類實(shí)現(xiàn)圖片顯示的JSP文件
          <%@page contentType="text/html; charset=GB2312"%>
          <%@page import="org.jfree.chart.ChartUtilities"%>
          <%@page import="org.jfree.chart.JFreeChart"%>
          <%@page import="com.mfsoft.net.jfreemap.DisplayMap" %>
          <%@page contentType="text/html; charset=GB2312"%>
          <%@page import="com.mfsoft.credit.modelmang.operation.EvalItemDataOperation" %>
          <%@page import="com.mfsoft.net.jfreemap.*" %>
          <%@page import="com.mfsoft.credit.modelmang.operation.ModelDataTypeOperation" %>

          <html>
          <head>
          <title>柱狀圖顯示結(jié)果</title>
          </head>
          <body>
          <%

           String timeType=(String)request.getParameter("timeType");
           String areaid=(String)request.getParameter("areaid");
           String areaType=(String)request.getParameter("areaType");
           String endTime=EvalItemDataOperation.getEndYearsToday();
           String startTime=EvalItemDataOperation.getNYearsToday(endTime,1);
           int lineScore=55000;
           int nnetScore=45632;
           int timeScore=50000;
           int moveWeightScore=60000;
           nnetScore=Integer.valueOf((String)request.getParameter("nnetScore"));
           lineScore=Integer.valueOf((String)request.getParameter("lineScore"));
           timeScore=Integer.valueOf((String)request.getParameter("timeScore"));
           moveWeightScore=Integer.valueOf((String)request.getParameter("moveWeightScore"));
              MoveWeightLineMap mp=new MoveWeightLineMap();
              double[][]st={{}};
              if(timeType!=null&&areaid!=null&&areaType!=null)
              {
                  if(timeType.equals("0"))
                  {
                      st=ModelDataTypeOperation.getMonthData(startTime,endTime,areaid,areaType);
                  }
                  else
                  if(timeType.equals("1"))
                  {
                      st=ModelDataTypeOperation.getThirdYearData(startTime,endTime,areaid,areaType);
                  }
                  else
                  if(timeType.equals("2"))
                  {
                      st=ModelDataTypeOperation.getHalfYearData(startTime,endTime,areaid,areaType);
                  }
                  else
                  {
                      st=ModelDataTypeOperation.getYearData(startTime,endTime,areaid,areaType);
                  }
               DisplayMap dm=new DisplayMap();
               JFreeChart chart=dm.displayResult(st,lineScore, nnetScore, moveWeightScore, timeScore);
               ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart,1000,600);
              }
              else
              {
                   out.print("傳遞過來的值為空,不能顯示柱狀圖");
              }
          %>
          </body>
          </html>

          posted on 2008-06-20 08:52 weesun一米陽光 閱讀(2045) 評(píng)論(2)  編輯  收藏 所屬分類: 總結(jié)備用

          評(píng)論

          # re: JfreeChar實(shí)現(xiàn)JSP頁面繪圖以及圖片顯示【原創(chuàng)】 2012-10-15 21:51 卞曉晨
          import com.mfsoft.credit.modelmang.operation.EvalItemDataOperation;
          import com.mfsoft.credit.modelmang.operation.ModelDataTypeOperation;
          import com.mfsoft.net.pre.MoveWeightAverage;
          import com.mfsoft.net.pre.TimeSeriesForecast;



          這些包如何找到?  回復(fù)  更多評(píng)論
            

          # re: JfreeChar實(shí)現(xiàn)JSP頁面繪圖以及圖片顯示【原創(chuàng)】 2012-10-16 09:41 waysun
          自定義的類@卞曉晨
            回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 左云县| 中西区| 嘉善县| 英山县| 迁西县| 博客| 华坪县| 澄城县| 浑源县| 会泽县| 兰考县| 龙岩市| 桦甸市| 如皋市| 道真| 石阡县| 栾城县| 蓬溪县| 涿鹿县| 渑池县| 青川县| 甘肃省| 舞钢市| 桂阳县| 叶城县| 镇宁| 兴海县| 通辽市| 扎赉特旗| 确山县| 韶山市| 天峨县| 阿瓦提县| 临潭县| 黄大仙区| 靖远县| 昭通市| 自治县| 日照市| 北宁市| 镇康县|