贤仁居 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 阅读(1333) | 评论 (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 阅读(8327) | 评论 (0)编辑 收藏
仅列出标题
共4页: 上一页 1 2 3 4