为折线图 jfreechart 创建自定义 x 轴标签
我创建了一个折线图,在 x 轴上每 10 分钟显示一次时间。数据可能长达一个月,因此 x 轴标签混合在一起(不可读)。此外,网格线靠得太近。我需要弄清楚如何隐藏 x 轴图表标签和网格线,并创建自定义标签和网格线以仅每小时显示(或者如果我需要显示 6 个月的图表,则可能每月显示)。目前,x 轴标签是日期时间格式。如果以 24 小时为图表,我只需要显示每小时的时间。如果绘制的时间超过 1 个月,我需要显示日期。
I created a line chart that displays time every 10 minutes on the x-axis. The data can be for a month long, so the x-axis labels are blended together (unreadable). Also, the grid lines are too close together. I need to figure out how to hide the x-axis chart labels and grid lines and create custom labels and grid lines to only show every hour (or maybe every month if I need to display the graph for a 6 month period). Currently, the x-axis labels are date time format. If 24 hour period is graphed, I need to only show the time every hour. If more than 1 month is graphed, I need to show the date.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意一个月的数据是6 * 24 * 30 = 4320;数值太多,无法精确查看,而 6 个月的情况更糟。作为替代方案,您可以幻灯片 或 分页数据集。默认轴标签应自动调整。如果您遇到问题,请发布 sscce。
Note that a month's data is 6 * 24 * 30 = 4320; that's too many values to view with much precision, and 6 moths is worse. As an alternative, you can slide or page the data set. The default axis labels should adjust automatically. If you have problems, please post an sscce.
10 分钟的刻度需要显示太多,您应该:
setAutoRange()
设置为true
有关日期和时间,请查看 DateTickUnit,对于一般数字,它是 NumberTickUnit
如果您可以确定显示的范围,那么只需创建正确的
DateTickUnit
即可。例如,如果是小时:您提到的网格线将与刻度线位于同一位置,因此这应该可以解决这两个问题。
The 10-minute ticks are way to much to display, instead you should either:
setAutoRange()
totrue
TickUnit
.For dates and time go check out DateTickUnit, and for numbers in general it is NumberTickUnit
If you can determine what range is displayed, it is only a matter of creating the correct
DateTickUnit
. If it for example is hours:The gridlines you mention will be the same place as the tick marks so this should solve both problems.