简体   繁体   中英

JFreeCharts TimeSeriesChart set domain interval

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?

在此处输入图片说明

If you add any RegularTimePeriod to a TimeSeries , the corresponding axis will use the inferred period as a guide to formatting. A related example that uses Day may be found here .

Addendum: See also this related answer concerning DateTickUnit .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM