2010-05-11 78 views

回答

2

StackedBarRenderer花費了一些努力使「條的間距和條寬度保持一致。」目前還不清楚,隨着列數的變化,你希望它做什麼不同。相關的幾何圖形由父BarRenderercalculateBarWidth()等方法確定,可根據需要重寫。另外,請確認每個系列中的每個類別都有一個值。

+1

我ü sed setMaximumBarWidth方法渲染器動態設置寬度。 – SKR 2010-05-20 03:10:35

+0

非常好。我不知道'setMaximumBarWidth()',它看起來更容易。我會把它作爲一個單獨的答案投票。 – trashgod 2010-05-20 05:13:22

3

在堆積條形圖,則可以使用

  • CategoryAxis.setLowerMargin
  • CategoryAxis.setMargin和
  • CategoryAxis.setUpperMargin

代碼如下

改變杆之間的間隔
protected JFreeChart generateGraph() { 

    CategoryAxis categoryAxis = new CategoryAxis("Categories"); 
    categoryAxis.setLowerMargin(.01); 
    categoryAxis.setCategoryMargin(.01); 
    categoryAxis.setUpperMargin(.01);  
    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); 

    ValueAxis valueAxis = new NumberAxis("Values"); 

    StackedBarRenderer renderer = new StackedBarRenderer(); 
    renderer.setBarPainter(new StandardBarPainter()); 
    renderer.setDrawBarOutline(false); 
    renderer.setShadowVisible(false); 
    renderer.setBaseItemLabelsVisible(true); 
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); 

    CategoryPlot plot = new CategoryPlot(_dataset, 
             categoryAxis, 
             valueAxis, 
             renderer); 

    plot.setOrientation(PlotOrientation.VERTICAL); 

    JFreeChart chart = new JFreeChart("Title", 
          JFreeChart.DEFAULT_TITLE_FONT, 
          plot, 
          true); 
    //ChartFactory.getChartTheme().apply(_chart); 
    return chart; 
}