TimeSeries override x-axis unit

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
fuahoik
Posts: 3
Joined: Tue Dec 02, 2008 9:37 am

TimeSeries override x-axis unit

Post by fuahoik » Tue Dec 02, 2008 10:02 am

Hi there,

I have created a TimeSeriesChart with four timeseries in which I would like to display different quarters on the x-axis an some numbers on the y-axis. No problem so far, works fine. But is it possible to override the Dateformat with an string like "Quarter 1", "Quarter 2", ... instead of displaying the first day of the current quarter ("01.01.2008", "01.04.2008",...)?

This is my current code:

Code: Select all

XYPlot plot = chart.getXYPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd.MM.yyyy")); 
DateTickUnit unit=new DateTickUnit(DateTickUnit.MONTH, 3,new SimpleDateFormat("dd.MM.yyyy"));
axis.setTickUnit(unit);
To add new values to a timeseries i use this piece of code:
...
tsStart.addOrUpdate(new Quarter(quartal, jahr), anzahl);
...


So I hope you understand what I mean, my english is not so good at all.
Thank you for your help!

fuahoik
Posts: 3
Joined: Tue Dec 02, 2008 9:37 am

Post by fuahoik » Tue Dec 02, 2008 10:05 am

here you can find a screenshot:

asj-essen.de/chart.jpg

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Dec 02, 2008 1:34 pm

In the code you quoted, you specify the date format using a SimpleDateFormat instance. Look up the QuarterDateFormat class in JFreeChart and use that instead.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

fuahoik
Posts: 3
Joined: Tue Dec 02, 2008 9:37 am

Post by fuahoik » Tue Dec 02, 2008 2:16 pm

Wow, thanks for your fast help! :D

I've had to be blind to miss that... :shock:

Code: Select all

String[] quarters={"1. Quartal", "2. Quartal", "3. Quartal", "4. Quartal"};
axis.setDateFormatOverride(new QuarterDateFormat(TimeZone.getDefault(),quarters));
unit=new DateTickUnit(DateTickUnit.MONTH, 3,new QuarterDateFormat(TimeZone.getDefault(), quarters));
Works fine, but the quarters are formatted like 2008 1. Quartal, 2008 2. Quartal..., how can I format it so that the year will be shown at the end ( 1. Quartal 2008)?

I have found the format method in the QuarterDateFormat class, but how do i use it in this case?

mramin05
Posts: 6
Joined: Mon Dec 15, 2008 5:52 am

Post by mramin05 » Thu Dec 18, 2008 1:43 am

fuahoik wrote:Wow, thanks for your fast help! :D

I've had to be blind to miss that... :shock:

Code: Select all

String[] quarters={"1. Quartal", "2. Quartal", "3. Quartal", "4. Quartal"};
axis.setDateFormatOverride(new QuarterDateFormat(TimeZone.getDefault(),quarters));
unit=new DateTickUnit(DateTickUnit.MONTH, 3,new QuarterDateFormat(TimeZone.getDefault(), quarters));
How can I apply this with PeriodAxis as I have hour in the domain axis.
I do not found setTickunit in periodAxis.
thx in advance.Amin

BO
Posts: 61
Joined: Wed Mar 01, 2006 2:17 pm

Re:

Post by BO » Tue Sep 27, 2011 7:07 pm

fuahoik wrote:Wow, thanks for your fast help! :D

I've had to be blind to miss that... :shock:

Code: Select all

String[] quarters={"1. Quartal", "2. Quartal", "3. Quartal", "4. Quartal"};
axis.setDateFormatOverride(new QuarterDateFormat(TimeZone.getDefault(),quarters));
unit=new DateTickUnit(DateTickUnit.MONTH, 3,new QuarterDateFormat(TimeZone.getDefault(), quarters));
Works fine, but the quarters are formatted like 2008 1. Quartal, 2008 2. Quartal..., how can I format it so that the year will be shown at the end ( 1. Quartal 2008)?

I have found the format method in the QuarterDateFormat class, but how do i use it in this case?

answer for the very old question :)

Code: Select all

axis.setDateFormatOverride(new QuarterDateFormat(TimeZone.getDefault(),quarters,[b]true[/b]));

Locked