JfreeChart: Stacked Bar Chart and CategoryAxis showing dates

后端 未结 2 746
故里飘歌
故里飘歌 2020-12-02 03:08

I have created a stacked bar chart in which I show a count on the y axis and dates on the x axis. The problem is that when I have many dates on the x

相关标签:
2条回答
  • 2020-12-02 03:17

    Have you tried overriding the generateLabel methods in the label generator? Something like:

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

    I haven't tested the code, but it should only output a label every 7 columns. More info on the label generator is here: http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/labels/CategoryItemLabelGenerator.html

    0 讨论(0)
  • 2020-12-02 03:27

    For a CategoryAxis, which is used the for the domain axis in a StackedBarChart, you have considerable flexility with the method setCategoryLabelPositions(). Typical usage is illustrated in the BarChartDemo1 source, shown here.

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    
    0 讨论(0)
提交回复
热议问题