2016-03-22 73 views
1

我正在使用JasperReports生成帶有圖表的報表。其中一個是條形圖,我想設置20個單位的軸值的增量。BarChart設定值軸增量

你可以看到我以前的方法在此鏈接:BarChart bar value labels are hidden by the margin

這是我的定製類:

public class BarChartCustomizer extends JRAbstractChartCustomizer { 

    @Override 
    public void customize(JFreeChart jFreeChart, JRChart jrChart) { 

     CategoryPlot plot = (CategoryPlot) jFreeChart.getPlot(); 
     plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); 
     NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 
     NumberFormat numberFormat = NumberFormat.getNumberInstance(); 
     numberFormat.setMaximumFractionDigits(2); 
     numberFormat.setMinimumFractionDigits(2); 
     rangeAxis.setNumberFormatOverride(numberFormat); 
     BarRenderer barRenderer = (BarRenderer) plot.getRenderer(); 
     barRenderer.setItemMargin(0.0); 
     rangeAxis.setUpperMargin(0.20); 
     rangeAxis.setAutoRange(true); 
     CategoryAxis categoryAxis = plot.getDomainAxis(); 
     categoryAxis.setAxisLineStroke(new BasicStroke(2f)); 
     rangeAxis = (NumberAxis) plot.getRangeAxis(); 
     rangeAxis.setAxisLineStroke(new BasicStroke(2f)); 
    } 
} 

我試着用rangeAxis.setMinorTickCount(20);沒有成功。

像往常一樣,最終的解決方案將包含在位於我的GitHub存儲庫中的樣本代碼:https://github.com/MichaelKnight/jaspertest.git

回答