日期:2014-05-17  浏览次数:20743 次

如何设置 jfreechart 柱体间的距离 和jfreechart在linux下的中文乱码问题
以下是柱状的设置的代码:

Java code

DefaultCategoryDataset dataset     =   new  DefaultCategoryDataset();
dataset.addValue( InnerTraffic/SampleRate ,  " 区域内流量流量 " ,  " 区域内流量流量 " );
dataset.addValue( InterTraffic/SampleRate ,  " 跨区域流量 " ,  " 跨区域流量 " );
dataset.addValue( AverageUserSpeed ,  " 域内平均下载速度 " ,  " 跨区域流量 " );
JFreeChart chart  =  ChartFactory.createBarChart3D( "流量统计图" , "统计周期(单位:天)" , " 流量大小(单位:kb) ,流量速度(单位:kb/s)" ,dataset,PlotOrientation.VERTICAL, true , false , false );
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot  =  chart.getCategoryPlot();
CategoryAxis domainAxis  =  plot.getDomainAxis();
// domainAxis.setVerticalCategoryLabels( false );
plot.setDomainAxis(domainAxis);
domainAxis.setMaximumCategoryLabelWidthRatio(1);
domainAxis.setCategoryMargin(0.01);
domainAxis.setLowerMargin(0.05);
domainAxis.setUpperMargin(0.05);
//中文乱码解决   
Font font = new Font("SimSun", 10, 12);    
// x轴外围字体   
plot.getDomainAxis().setLabelFont(font);   
// x轴刻度字体   
plot.getDomainAxis().setTickLabelFont(font);   
// y轴外围字体   
plot.getRangeAxis().setLabelFont(font);   
// y轴刻度字体   
plot.getRangeAxis().setTickLabelFont(font);   
// 标题字体   
chart.getTitle().setFont(font);
// 下面   
chart.getLegend().setItemFont(font);
        BarRenderer3D renderer  =   new  BarRenderer3D();
        renderer.setBaseOutlinePaint(Color.BLACK);

         // 设置每个地区所包含的平行柱的之间距离
         renderer.setItemMargin(0.01);
         // 显示每个柱的数值,并修改该数值的字体属性
        renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        renderer.setItemLabelsVisible(true);
        plot.setRenderer(renderer);

         //  设置柱的透明度
        plot.setForegroundAlpha(0.8f);
         renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
                ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
   String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
   String graphURL =request.getContextPath()+"/DisplayChart?filename="+filename;




图片如下:


我要设置每组的柱体之间的距离,应该如何设置?

这个比较紧急,大家帮忙看看。

还有就是jfreechart 在linux下 中文字体出现乱码。


------解决方案--------------------
定一下,之前也遇到了没有解决。中文问题应该是linux下没有中文字体包导致的。
------解决方案--------------------
樓主要設置每個柱狀之間的距離嗎?

setMaximumMargin()和setMinimumMargin() 兩個距離設置成相等的就好了