JFreeChart 全面讲解(san)

 
public   class  ChartUtil {    
     
//字体  
  
     
private 
  
static 
  
final 
 Font PLOT_FONT =  
new  
 Font( 
"黑体" 
, Font.ITALIC ,  
18 
);   
     
/**    
     * 创建数据集合    
     * @return XYDataset对象    
     */    
     
public 
  
static 
 XYDataset createDataset() {   
         
//实例化TimeSeries对象  
  
        TimeSeries timeseries =  
new 
 TimeSeries( 
"Data" 
);   
        Day day =  
new 
 Day( 
112008 
);   
//实例化Day  
  
         
double 
 d = 3000D;   
         
//添加一年365天的数据  
  
         
for 
 ( 
int 
 i =  
0 
; i <  
365 
; i++) {    
            d = d + (Math.random() -  
0.5 
) *  
10//创建随机数据  
  
            timeseries.add(day, d);  
//向数据集合中添加数据  
  
            day = (Day) day.next();    
        }   
         
//创建TimeSeriesCollection集合对象  
  
        TimeSeriesCollection timeSeriesCollection =  
new 
 TimeSeriesCollection(timeseries);   
         
//返回数据集合对象  
  
         
return 
 timeSeriesCollection;   
    }   
     
/**    
     * 生成制图对象    
     * @return JFreeChart对象    
     */    
     
public 
  
static 
 JFreeChart createChart(){   
         
//创建时序图对象  
  
        JFreeChart chart = ChartFactory.createTimeSeriesChart(   
                 
"编程词典全国销量统计" 
,        
//标题  
  
                 
"销售月份" 
,                  
//时间轴标签  
  
                 
"销量(份)" 
,                 
//数据轴标签  
  
                createDataset(),                 
//数据集合  
  
                 
false 
,                   
//是否显示图例标识  
  
                 
false 
,                       
//是否显示tooltips  
  
                 
false 
);                  
//是否支持超链接  
  
         
//设置标题字体  
  
        chart.getTitle().setFont( 
new 
 Font( 
"隶书" 
, Font.BOLD,  
26 
));   
         
//设置背景色  
  
        chart.setBackgroundPaint( 
new 
 Color( 
252 
, 
175 
, 
134 
));   
        XYPlot plot = chart.getXYPlot();         
//获取图表的绘制属性  
  
        plot.setDomainGridlinesVisible( 
false 
);   
//设置网格不显示  
  
         
//获取时间轴对象  
  
        DateAxis dateAxis = (DateAxis) plot.getDomainAxis();   
        dateAxis.setLabelFont(PLOT_FONT);    
//设置时间轴字体  
  
         
//设置时间轴标尺值字体  
  
        dateAxis.setTickLabelFont( 
new 
 Font( 
"宋体" 
,Font.PLAIN, 
12 
));   
        dateAxis.setLowerMargin( 
0.0 
);        
//设置时间轴上显示的最小值  
  
         
//获取数据轴对象  
  
        ValueAxis valueAxis = plot.getRangeAxis();   
        valueAxis.setLabelFont(PLOT_FONT);   
//设置数据字体  
  
        DateFormat format =  
new 
 SimpleDateFormat ( 
"MM月份" 
);    
//创建日期格式对象  
  
         
//创建DateTickUnit对象  
  
        DateTickUnit dtu =  
new 
 DateTickUnit (DateTickUnitType.DAY, 
29 
,format);   
        dateAxis.setTickUnit(dtu);           
//设置日期轴的日期标签  
  
         
return 
 chart;   
    }   
}
                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值