在JFreeChart中隐藏一些类别标签以避免重叠 [英] Hide some category labels in JFreeChart to avoid overlapping

查看:156
本文介绍了在JFreeChart中隐藏一些类别标签以避免重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JFreeChart生成StackedBarChart.根据输入数据,我可以有很多类别(通常在20到40之间),导致标签重叠. 在下面的屏幕截图中,您可以看到类别从1到38的图表:

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 labels. In the following screenshot you can see the chart with categories from 1 to 38:

我想显示一些类别标签作为参考,但不是全部.最好显示第一个和最后一个,以及之间的每五个. 这可能吗?

I'd like to show some of the category labels as reference, but not all. It would be perfect to show the first and last, and every fifth inbetween. Is this possible?

我无法更改图表的宽度,并且使标签变小仅在它们太小以至于您无法阅读它们时才起作用... 最后的选择是隐藏整个类别轴...

I can't change the width of the chart, and making the labels smaller does only work if they are so small that you can't read them anymore... Last resort would be to hide the whole category axis...

谢谢您的建议!

推荐答案

一种简单的解决方案是将类别"标签设置为背景色(在这种情况下为白色).

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

这篇关于在JFreeChart中隐藏一些类别标签以避免重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆