2010-05-11 138 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; 
} 
相关问题