【问题标题】:JfreeChart: Stacked Bar Chart and CategoryAxis showing datesJfreeChart:显示日期的堆积条形图和 CategoryAxis
【发布时间】:2012-08-24 02:58:24
【问题描述】:

我创建了一个堆积条形图,其中我在 y 轴上显示计数,在 x 轴上显示日期。问题是当我在 x 轴上有很多日期时,它会变得非常混乱且无法阅读。我想只显示一些日期,例如每周一个日期。那可能吗?我正在使用ChartFactory.createStackedBarChart() 创建图表,并且我在DefaultCategoryDataSet 中有数据。

感谢任何输入!

【问题讨论】:

    标签: charts jfreechart bar-chart


    【解决方案1】:

    您是否尝试过覆盖标签生成器中的 generateLabel 方法?比如:

    chart.getCategoryPlot().getRenderer().setBaseItemLabelGenerator(
      new CategoryItemLabelGenerator() {
    
        public String generateColumnLabel(CategoryDataset dataset, Integer column) {
          if(column % 7 == 0)
            super.generateColumnLabel(dataset, column)
          else 
            ""
        }
      }
    );
    

    我没有测试过代码,但它应该只每 7 列输出一个标签。关于标签生成器的更多信息在这里:http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/labels/CategoryItemLabelGenerator.html

    【讨论】:

      【解决方案2】:

      对于在StackedBarChart 中用于域轴的CategoryAxis,使用setCategoryLabelPositions() 方法具有相当大的灵活性。典型用法在BarChartDemo1 源中进行了说明,显示为here

      CategoryAxis domainAxis = plot.getDomainAxis();
      domainAxis.setCategoryLabelPositions(
          CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
      

      【讨论】:

      • 上次看到here
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2018-11-30
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多