Currently I have a TimeSeries chart which displays dates on the x-axis. I've noticed the JFreeChart seems to kind of "guess" at what time intervals should be displayed (monthly, weekly, etc..) based on the range of data you provide. Is there a way to let my user choose what intervals are to be displayed at runtime? For instance, they may want to see an interval of one week or every 2 weeks; 1 month or every two months, etc...
Thanks,
Craig.
Time interval on the x-axis
Re: Time interval on the x-axis
Craig,
You'll have to turn off the AutoTickUnit functionality first, then set your own interval using the fields from the Calendar class. You can then format the the tick labels using SimpleDateFormat.
Here's a snippet:
Plot plot = yourChart.getPlot();
HorizontalDateAxis hdAxis = (HorizontalDateAxis) plot.getHorizontalAxis ();
hdAxis.setAutoTickUnitSelection(false);
hdAxis.setTickUnit(new DateUnit(Calendar.MONTH, 2));
SimpleDateFormat sdf = hdAxis.getTickLabelFormatter();
sdf.applyPattern("M/yyyy");
DateUnit allows you to use the following fields from the Calendar class: YEAR, MONTH, DATE/DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND.
Troy
You'll have to turn off the AutoTickUnit functionality first, then set your own interval using the fields from the Calendar class. You can then format the the tick labels using SimpleDateFormat.
Here's a snippet:
Plot plot = yourChart.getPlot();
HorizontalDateAxis hdAxis = (HorizontalDateAxis) plot.getHorizontalAxis ();
hdAxis.setAutoTickUnitSelection(false);
hdAxis.setTickUnit(new DateUnit(Calendar.MONTH, 2));
SimpleDateFormat sdf = hdAxis.getTickLabelFormatter();
sdf.applyPattern("M/yyyy");
DateUnit allows you to use the following fields from the Calendar class: YEAR, MONTH, DATE/DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND and MILLISECOND.
Troy