Hide some category labels in JFreeChart to avoid overlapping

后端 未结 2 640
走了就别回头了
走了就别回头了 2020-12-12 00:14

I\'m generating a StackedBarChart using JFreeChart. Depending on the input data I can have a lot of categories (usually between 20 and 40), leading to overlapping of the lab

相关标签:
2条回答
  • 2020-12-12 00:19

    You can use setVerticalTickLabels(true) on your domain axis, as shown in this example.

    Addendum: Oops, the example cited is for a ValueAxis. For a CategoryAxis, as used in StackedBarChart, you have even more flexility with the method setCategoryLabelPositions(). Typical usage is illustrated in the BarChartDemo1 source, shown here.

    0 讨论(0)
  • 2020-12-12 00:32

    One simple solution is to set the Category lables to the backround colour (in this case white).

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setTickLabelPaint("Category 2", Color.white);
        domainAxis.setTickLabelPaint("Category 4", Color.white);
    

    This will produce a chart like this

    enter image description here

    0 讨论(0)
提交回复
热议问题