width - 在 JFreeChart 中修复条形图宽度和条形之间的间距

标签 width jfreechart bar-chart

我有堆叠条形图,其中列数是动态的,可以从 1 列更改为 n 列。我希望图表之间的间距和条形图的宽度保持一致。我如何解决它。请提出解决方案/想法。

最佳答案

在堆积条形图中,您可以使用

  • 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;
    }
    

    关于width - 在 JFreeChart 中修复条形图宽度和条形之间的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2808093/

    相关文章:

    html - 当列宽总和 != 表格宽度时,行为是什么?

    java - 在 CombinedDomainXYPlot 中创建标记/十字线

    java - JFreechart 主图像(不包括 YLabel)宽度因地 block 而异

    jquery - jqplot 和条形图中条形和 Y 轴的不同缩放比例

    ios - 当用户点击图表时创建一个 MarkerView

    css - div 未使用可用空间(div :inline-block, 位置:固定)

    javascript - 在 em 中获取 CSS 中定义的元素的宽度

    html - 如何设置宽度以包括浏览器滚动条?

    Java&JFreeChart - 如何设置 JFreeChart 的 ChartPanel 随其容器(例如 JPanel )调整大小?

    java - 如何使用 ObservableLists 在 Javafx 中创建条形图或折线图