Hide some category labels in JFreeChart to avoid overlapping

岁酱吖の 提交于 2019-11-28 14:05:38

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

trashgod

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!