JFreeCharts TimeSeriesChart 设置域间隔
如何在TimeSeriesChart中设置Domain轴的时间间隔? 现在我有带有标签的域轴,看起来像:22.00 23.00、00.00、1.00、2.00 等。
我如何将它们设置为:2 月 11 日、2 月 12 日等。 仅当我缩放图表时,我才应该能够看到所有时间。
编辑:现在我在 SimpleDateFormat
的帮助下解决了这个问题。
DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
DateFormatSymbols dfs = DateFormatSymbols.getInstance(); // default locale
dateAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-HH:mm", dfs));
显示的图表:
编辑:问题仍然悬而未决:是否可以设置诸如按天分组之类的内容域轴?
编辑:更多信息:) 我尝试获取上周的一些数据,但如果数据库中的数据仅持续 1 或 2 天,图表将如下所示:
因为您可以在域轴上看到时间轴存储从 00.00(实际开始时间为 23.xx)到的信息10.00,这不好,因为用户应该看到数据所属的日期。在这种情况下,我创建 TimeSeries 并填充它,如下所示:
TimeSeries ts=new TimeSeries(name);
ts.addOrUpdate(new Hour(date), value);
如果我像
ts.addOrUpdate(new Day(date), value);
这样填充 ts,则图表不会显示任何数据
问题是如何按天制作图表组数据(也许可以借助缩放),如下图所示?
How to set time interval for Domain axis in TimeSeriesChart?
Now i have domain axis with labels which looks something like: 22.00 23.00, 00.00, 1.00, 2.00, etc.
How can I set them like: 11 feb, 12 feb etc.
I should have posibility to see all hourse only if I zoom chart.
Edit: Now I solve it with the help of SimpleDateFormat
.
DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
DateFormatSymbols dfs = DateFormatSymbols.getInstance(); // default locale
dateAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-HH:mm", dfs));
Chart displayed :
Edit: The question is still open: Is it possible to set something like grouping by day for domain axis?
Edit: More information:)
I try to get some data for last week period, but if data in database only for 1 or 2 days, chart will look like this:
as you can see timline on domain axis store information from 00.00(actualy start time is 23.xx) till 10.00, and it's no good, because user should see day which data belongs. In this case I create TimeSeries and fill it like :
TimeSeries ts=new TimeSeries(name);
ts.addOrUpdate(new Hour(date), value);
If I fill ts like
ts.addOrUpdate(new Day(date), value);
then chart didn't show any data
Quistion is how to make chart group data (maybe with the help of zoom ) by days, like in the following chart?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您添加任何
RegularTimePeriod
到
TimeSeries
,相应的轴将使用推断的周期作为格式化的指导。使用Day
的相关示例可以在此处找到。附录:另请参阅有关
DateTickUnit
的相关答案。If you add any
RegularTimePeriod
to aTimeSeries
, the corresponding axis will use the inferred period as a guide to formatting. A related example that usesDay
may be found here.Addendum: See also this related answer concerning
DateTickUnit
.