柱状图设置

Java代码 复制代码
  1. 使用JFreeChart 输出柱状图 基本参数设置:  
使用JFreeChart 输出柱状图 基本参数设置:
Java代码 复制代码
  1.   
 
Java代码 复制代码
  1. package com.*****************.domain.util;   
  2.   
  3. import java.awt.Color;   
  4. import java.awt.Font;   
  5. import java.text.DecimalFormat;   
  6.   
  7. import org.jfree.chart.JFreeChart;   
  8. import org.jfree.chart.axis.CategoryAxis;   
  9. import org.jfree.chart.axis.NumberAxis;   
  10. import org.jfree.chart.axis.ValueAxis;   
  11. import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;   
  12. import org.jfree.chart.plot.CategoryPlot;   
  13. import org.jfree.chart.renderer.category.BarRenderer;   
  14.   
  15. /**  
  16.  * 格式化 JFreeChart 输出图片  
  17.  *   
  18.  *     
  19.  * Author :   
  20.  * Date   : Nov 26, 2009  
  21.  * Time   : 11:50:41 AM   
  22.  * Version: 1.0  
  23.  */  
  24. public class FormatPic {   
  25.     /**  
  26.      * 格式化纵向柱状图使用  
  27.      *   
  28.      * @param chart  
  29.      * @returnType: void  
  30.      * @author:   
  31.      * @data: Nov 26, 2009  
  32.      * @time: 11:51:26 AM  
  33.      */  
  34.     public static void setView(JFreeChart chart){   
  35. //      初始化字体   
  36.         Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 12);   
  37.         Font noFont = new Font("SansSerif", Font.TRUETYPE_FONT, 48);   
  38. //      格式化 图片     
  39.         CategoryPlot plot = chart.getCategoryPlot();   
  40. //        没有数据是显示的消息   
  41.         plot.setNoDataMessage("没有数据!");   
  42. //        没有数据时显示的消息字体   
  43.         plot.setNoDataMessageFont(noFont);    
  44. //        没有数据时显示的消息颜色   
  45.         plot.setNoDataMessagePaint(Color.RED);     
  46.      // 数据轴精度    
  47.         NumberAxis vn = (NumberAxis) plot.getRangeAxis();    
  48.      // 数据轴数据标签的显示格式    
  49.         CategoryAxis domainAxis = plot.getDomainAxis();    
  50.            
  51.      // 设置刻度必须从0开始    
  52.         vn.setAutoRangeIncludesZero(true);   
  53. //      设置纵坐标数据精度   
  54. //        DecimalFormat df = new DecimalFormat("#0.00");    
  55. //        vn.setNumberFormatOverride(df);   
  56.            
  57.            
  58. //     x轴设置    
  59.         domainAxis.setLabelFont(labelFont);// 轴标题    
  60.         domainAxis.setTickLabelFont(labelFont);// 轴数值   
  61. //     y轴设置    
  62.         ValueAxis rangeAxis = plot.getRangeAxis();    
  63.         rangeAxis.setLabelFont(labelFont);    
  64.         rangeAxis.setTickLabelFont(labelFont);          
  65.            
  66.         BarRenderer renderer = new BarRenderer();    
  67.         // 设置柱子宽度    
  68.         renderer.setMaximumBarWidth(0.05);    
  69.         // 设置柱子高度    
  70. //        renderer.setMinimumBarLength(0.2);    
  71.         // 设置柱子边框颜色    
  72.         renderer.setBaseOutlinePaint(Color.BLACK);    
  73.         // 设置距离图片左端距离    
  74.         domainAxis.setLowerMargin(0.01);    
  75.         // 设置距离图片右端距离    
  76. //        domainAxis.setUpperMargin(0.2);    
  77.            
  78.       // 设置显示位置   
  79. //        plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);   
  80. //        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);   
  81.   
  82.         plot.setDomainAxis(domainAxis);    
  83.         // 设置柱图背景色(注意,系统取色的时候要使用16位的模式来查看颜色编码,这样比较准确)    
  84.         plot.setBackgroundPaint(new Color(255255204));    
  85.            
  86.      // 设置每个平行柱之间距离    
  87.         renderer.setItemMargin(0.05);    
  88.         // 显示每个柱的数值,并修改该数值的字体属性    
  89.         renderer.setIncludeBaseInRange(true);    
  90.         renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());    
  91.         renderer.setBaseItemLabelsVisible(true);    
  92.            
  93.         plot.setRenderer(renderer);   
  94.     }   
  95. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值