jfreechart 生成报表 (1.0.6)

if("bzt".equals(tu)){ 
        // 生成3D饼图 
PiePlot3D plot = new PiePlot3D(getDataset()); 
        plot.setToolTipGenerator(new StandardPieToolTipGenerator()); 
        // 设置图片链接 
        plot.setURLGenerator(new StandardPieURLGenerator( 
                "")); 

        JFreeChart chart = new JFreeChart("", 
                JFreeChart.DEFAULT_TITLE_FONT, plot, true); 
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));         
        
        chart.setBackgroundPaint(Color.gray); 
        ChartUtilities.saveChartAsJPEG(new File(path), chart, 950, 600); 
        
}else{ 
//柱状图 

CategoryDataset dataset = getDataSet2(); 

JFreeChart chart = ChartFactory.createBarChart3D( 
"", // 图表标题 
"" , // 目录轴的显示标签 
"", // 数值轴的显示标签 
dataset, // 数据集 
PlotOrientation.VERTICAL, // 图表方向:水平、垂直 
true, // 是否显示图例(对于简单的柱状图必须是false) 
true, // 是否生成工具 
false // 是否生成URL链接 
); 
//CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryPlot plot = chart.getCategoryPlot(); 
//设置网格背景颜色   
plot.setBackgroundPaint(Color.white);  
//设置网格竖线颜色   
plot.setDomainGridlinePaint(Color.pink);  
//设置网格横线颜色   
plot.setRangeGridlinePaint(Color.pink);

plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); 
//plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); 


CategoryAxis domainAxis = plot.getDomainAxis(); 
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // X轴上的Lable让其45度倾斜 

BarRenderer3D renderer = new BarRenderer3D();  
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());  
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT)); 
renderer.setItemLabelFont(new   Font("黑体",Font.PLAIN,13)); 
//数据显示在柱上的位置 
renderer.setItemLabelAnchorOffset(12D); 
//每个分类之间的间隔 
renderer.setItemMargin(0.3); 
renderer.setSeriesVisibleInLegend(true); 

renderer.setBaseItemLabelsVisible(true); 
plot.setRenderer(renderer);  

FileOutputStream fos_jpg = null; 
try { 
fos_jpg = new FileOutputStream(new File(path)); 
ChartUtilities.writeChartAsJPEG(fos_jpg,1.0f,chart,950,600,null); 
} finally { 
try { 
fos_jpg.close(); 
} catch (Exception e) {} 
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值