A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
raunakkathuria
- Posts: 16
- Joined: Wed Dec 22, 2010 5:35 pm
- antibot: No, of course not.
- Location: India
-
Contact:
Post
by raunakkathuria » Thu Dec 23, 2010 6:09 am
Hi
I have designed a
StackedXYAreaChart with domain axis as
DateAxis and need a way to configure the tick units of DateAxis
Code I have used is
Code: Select all
DateTickUnit unit = null;
unit = new DateTickUnit(DateTickUnit.YEAR, 1);
axis.setTickUnit(unit);
but Tick Units always start from Jan i.e the time line shows Jan 1997, Jan 1998 and so on as shown in image below
http://www.raunakkathuria.com/images/jf ... actual.jpg
How can I configure the tick unit according to the month I need rather than starting from Jan.
Thanks
Raunak Kathuria
-
lfkpoa
- Posts: 7
- Joined: Wed Dec 22, 2010 8:28 pm
- antibot: No, of course not.
Post
by lfkpoa » Thu Dec 23, 2010 2:04 pm
Hi,
All you have to do is to override the date formatter from the DateAxis, like this:
Code: Select all
DateFormat formatter = new SimpleDateFormat("yyyy");
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(formatter);
But you can also set the tick unit with the formatter, if you don't want to rely on the auto tick unit selection:
Code: Select all
DateFormat formatter = new SimpleDateFormat("yyyy");
DateTickUnit unit = new DateTickUnit(DateTickUnit.YEAR, 1, formatter);
axis.setTickUnit(unit);
With regards,
Luis Fernando
-
raunakkathuria
- Posts: 16
- Joined: Wed Dec 22, 2010 5:35 pm
- antibot: No, of course not.
- Location: India
-
Contact:
Post
by raunakkathuria » Thu Dec 23, 2010 6:09 pm
Hi
Thanks for your reply.
Have already implemented the code that you have specified. Actually I want to change the month that appear on dateaxis, by default when i specify year as tick unit, it display Jan 1997 where i have used "MMM yyyy" as date format.
What i want is rather than displaying Jan as month, it should display the value of month that I will send it as parameter.
Thanks
Raunak Kathuria
-
lfkpoa
- Posts: 7
- Joined: Wed Dec 22, 2010 8:28 pm
- antibot: No, of course not.
Post
by lfkpoa » Fri Dec 24, 2010 2:49 pm
You can use setDateTickMarkPosition to change to the middle or the end of the tick unit (year in your case).
But it's not possible to choose the exact month the DateAxis will use for the tick besides the DateTickMarkPosition.
But you can extend the DateAxis and override previousStandardDate method to set the month used when the unit is year.
Take a look at the DateAxis source code.