賢仁居 George Gong
          It's never too late to learn
          posts - 32,comments - 16,trackbacks - 0

          以下代碼用到了大多數方法(附有注釋):

           private String createBarChart(String[] series,String[] categories,double[][] data,HttpSession session,PrintWriter printWriter){
                   
                 CategoryDataset dataset 
          = DatasetUtilities.createCategoryDataset(series, categories, data);
            
              JFreeChart chart 
          = ChartFactory.createBarChart3D("預算統計圖""預算科目","實際執行額",
                       dataset,PlotOrientation.VERTICAL,
          true,true,false);
                 
                 chart.setBackgroundPaint(Color.WHITE);   
          //設定背景色為白色
                 
                 CategoryPlot categoryPlot 
          = chart.getCategoryPlot();  //獲得 plot:CategoryPlot!!
                 
                 categoryPlot.setBackgroundPaint(Color.lightGray); 
          //設定圖表數據顯示部分背景色
                 
                 categoryPlot.setDomainGridlinePaint(Color.white); 
          //橫坐標網格線白色
                 categoryPlot.setDomainGridlinesVisible(true); //可見
                 
                 categoryPlot.setRangeGridlinePaint(Color.white); 
          //縱坐標網格線白色
               
                 CategoryAxis domainAxis 
          = categoryPlot.getDomainAxis();
                 
                 
          //設置 categoryAxis 垂直顯示
               domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.4));
               
               
          //設置哼坐標軸的標題字體,此處是“預算科目”
                  domainAxis.setLabelFont(new Font("SansSerif",Font.PLAIN,13));
                 
                 
          //設置距離圖片左端距離,參數為圖片的百分比
                 domainAxis.setLowerMargin(0.05);
                 
                 
          //設置距離圖片右端距離
                 domainAxis.setUpperMargin(0.05);
                     
                 
          //設置橫坐標的坐標值的字體
                 domainAxis.setTickLabelFont(new Font("SansSerif",Font.PLAIN,12));
                 
                 categoryPlot.setDomainAxis(domainAxis); 
                      
                 ValueAxis rangeAxis 
          = categoryPlot.getRangeAxis();
                 
          //設置最高的一個柱與圖片頂端的距離
                 rangeAxis.setUpperMargin(0.05);
                 
                 
          //設置最低的一個柱與圖片底端的距離
                 rangeAxis.setLowerMargin(0.05);
                 categoryPlot.setRangeAxis(rangeAxis); 
                 
                 
          //設置豎坐標標簽的旋轉角度
                 rangeAxis.setLabelAngle(0.05);
                 
                 
          //設置豎坐標軸的坐標值字體
          //       rangeAxis.setTickLabelFont(new Font("SansSerif",Font.PLAIN,12));
            
                 BarRenderer3D renderer
          =(BarRenderer3D) categoryPlot.getRenderer();
                 
                 renderer.setBaseOutlinePaint(Color.GREEN);
                 
          //設置 Wall 的顏色
                 renderer.setWallPaint(Color.PINK);
                 
                 
          //設置每個柱的顏色     
                 GradientPaint gradientpaint = new GradientPaint(0.0F0.0F, Color.blue,
                          
          0.0F0.0Fnew Color(0064)); //設定特定顏色
            GradientPaint gradientpaint1 = new GradientPaint(0.0F0.0F, Color.green,
                     
          0.0F0.0Fnew Color(0640));
           
                 renderer.setSeriesPaint(
          0, gradientpaint);
                 renderer.setSeriesPaint(
          1, gradientpaint1);
                 
                 
          //設置柱的 Outline 顏色
                 renderer.setSeriesOutlinePaint(0, Color.BLACK);
                 renderer.setSeriesOutlinePaint(
          1, Color.BLACK);
                 
          //設置每個category所包含的平行柱的之間距離
                 renderer.setItemMargin(0.1);
              
                 
          //顯示每個柱的數值,并修改該數值的字體屬性
                 renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
                 
                 
          //設置柱子上數值的字體
                 renderer.setItemLabelFont(new Font("SansSerif",Font.PLAIN,13));  
                 renderer.setItemLabelsVisible(
          true);
               
                 
          //設置柱子上數據的顏色
                 renderer.setItemLabelPaint(Color.RED);
                 
                 
          //設置bar的最小寬度,以保證能顯示數值
                 renderer.setMinimumBarLength(0.02);
                 
                 
          //最大寬度
                 renderer.setMaximumBarWidth(0.07);
                 
                 
                 
          //設置柱子上顯示的數據旋轉90度,最后一個參數為旋轉的角度值/3.14
                 ItemLabelPosition itemLabelPosition= new ItemLabelPosition(
                   ItemLabelAnchor.INSIDE12,TextAnchor.CENTER_RIGHT,
                   TextAnchor.CENTER_RIGHT,
          -1.57D);
                 
                 
          //設置不能在柱子上正常顯示的那些數值的顯示方式,將這些數值顯示在柱子外面
                 ItemLabelPosition itemLabelPositionFallback=new ItemLabelPosition(
                   ItemLabelAnchor.OUTSIDE12,TextAnchor.BASELINE_LEFT,
                   TextAnchor.HALF_ASCENT_LEFT,
          -1.57D);
                 
                 
          //設置正常顯示的柱子label的position
                 renderer.setPositiveItemLabelPosition(itemLabelPosition);
                 renderer.setNegativeItemLabelPosition(itemLabelPosition);
                 
                 
          //設置不能正常顯示的柱子label的position
                 renderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
                 renderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);
                 
                 categoryPlot.setRenderer(renderer);
                 
          //設置柱子的透明度
                 categoryPlot.setForegroundAlpha(0.8f);
                 
                 
          //設置地區、銷量的顯示位置
          //       categoryPlot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
          //       categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); 
                
                 StandardEntityCollection sec 
          = new StandardEntityCollection(); 
                 ChartRenderingInfo info 
          = new ChartRenderingInfo(sec);
                       
                 
          try {
                   ServletUtilities.setTempFilePrefix(
          "zcz");
                   ServletUtilities.setTempOneTimeFilePrefix(
          "zcz-onetime");
                  
                     filename 
          = ServletUtilities.saveChartAsPNG(chart, 926555, info, session);   
                     chartName
          =filename;
                     
                     System.out.println(
          "圖片的臨時保存路徑:"+System.getProperty("java.io.tmpdir"));
                 }
           catch (IOException ex) {
                     ex.printStackTrace();
                 }

                    
                     String myMap
          =ChartUtilities.getImageMap(filename, info);
                     printWriter.println(myMap);
              
               
          return filename;
              }
          posted @ 2007-07-23 10:47 George Gong 閱讀(1357) | 評論 (2)編輯 收藏

          選取Apache HTTP Server作為前端的負載服務器,后端選取兩個Tomcat作集群,此次選擇的配置方式為Session Sticky(粘性Session),這種方式將同一用戶的請求轉發到特定的Tomcat服務器上,避免了集群中Session的復制,缺點是用戶只跟一種的一臺服務器通信,如果此服務器down掉,那就廢了。
          采用的model為mod_proxy_ajp.so,整個配置在tomcat的配置文件中都有相關的注釋,只需作相應修改就OK。
          我們選取的是Apache HTTP Server2.2.4,Tomcat5.5.16。
          首先安裝Apache HTTP Server,然后修改其配置文件http.conf,首先load三個model,代碼如下:

          LoadModule proxy_module modules/mod_proxy.so
          LoadModule proxy_ajp_module modules
          /mod_proxy_ajp.so
          LoadModule proxy_balancer_module modules
          /mod_proxy_balancer.so
          然后在此配置文件末端加入以下代碼:
          ProxyPass / balancer://tomcatcluster/ lbmethod=byrequests stickysession=JSESSIONID nofailover=Off timeout=5 maxattempts=3  
          ProxyPassReverse / balancer://tomcatcluster/   
            
          <Proxy balancer://tomcatcluster>  
          BalancerMember ajp://localhost:8009 route=a  
          BalancerMember ajp://localhost:9009 route=b
          </Proxy> 

          以上代碼配置了Proxy的相關參數,<Proxy>模塊定義了均衡負載的配置,其中兩個Tomcat Server都配置在同一臺服務器上,端口分別為8009、9009,并配置各自的route,這樣Apache Server就能根據route將請求轉發給特定的Tomcat。
          接下來修改Tomcat的server.xml文件,如下:
          <!-- Define an AJP 1.3 Connector on port 8009 -->
              
          <Connector port="8009" 
                         enableLookups
          ="false" redirectPort="8443" protocol="AJP/1.3" />
          其中的port為前面<Proxy>中設定的端口,還要配置其route,代碼如下:
          <!-- Define the top level container in our container hierarchy -->
              
          <Engine name="Catalina" defaultHost="localhost" jvmRoute="a">
          jvmRoute也須同前面的設置一樣。

          下面用JMeter對配置后的負載均衡做一測試,首先先啟動兩個Tomcat Server,隨后啟動Apache Server,在JMeter中新建測試計劃,在兩個Tomcat Server中的jsp-examples下新建test.jsp(此jsp自己隨便寫兩句就成),然后進行測試,以下是部分取樣器結果:
          HTTP response headers:
          HTTP/1.1 200 OK
          Date: Wed, 11 Jul 2007 02:17:55 GMT
          Set-Cookie: JSESSIONID=AC7EF1CAA8C6B0FEB68E77D7D375E2AF.bPath=/jsp-examples
          Content-Type: text/html;charset=ISO-8859-1
          Content-Length: 3
          Keep-Alive: timeout=5, max=79
          Connection: Keep-Alive
          以上紅色代碼表示用戶的http請求中的JSESSIONID中已經附帶了route后綴,.b表示此請求將轉發到route為b的Tomcat Server上,你將會發現其中的一部分請求的JSESSIONID后綴為.a,也就是轉發給route為a的Tomcat Server上。
          posted @ 2007-07-11 10:08 George Gong 閱讀(8355) | 評論 (0)編輯 收藏
          僅列出標題
          共4頁: 上一頁 1 2 3 4 
          主站蜘蛛池模板: 兰溪市| 平昌县| 察哈| 庆云县| 嘉义市| 吴忠市| 新密市| 乌什县| 集贤县| 罗田县| 安顺市| 清徐县| 定南县| 都昌县| 平度市| 蚌埠市| 逊克县| 黄山市| 秀山| 太保市| 西安市| 望谟县| 龙岩市| 集安市| 博湖县| 南雄市| 上栗县| 留坝县| 桐柏县| 新绛县| 仁寿县| 石柱| 邳州市| 开平市| 兴义市| 沙雅县| 镇安县| 洪洞县| 新余市| 民县| 修水县|