rang Axis X & tickLabel

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
BO
Posts: 61
Joined: Wed Mar 01, 2006 2:17 pm

rang Axis X & tickLabel

Post by BO » Thu Sep 22, 2011 6:04 pm

Hi
on a axis, how can I change the tickLabel that are diffents from the real values?

my Axis X is based on date of year that have 3 possibles:
- week (1 -> 52 or 53)
- month (1 -> 12)
- quarter (1 -> 4)

the problem occurs if the rangs are over on 2 years
for ex: the rang is from 01/12/2010 to 05/03/2011 and i want to display with format 'week'
in this cas, the real rang in 'week' is from 48/2010, 49/2010, 50/2010, 51/2010, 52/2010, 01/2011, 02/2011 ... 09/2011

Could you tell me how to display on axis X the values 48, 49, 50, 51, 52, and then 1, 2, .... 9

thanks a lot
BO
Last edited by BO on Wed Sep 28, 2011 6:52 am, edited 1 time in total.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: rang Axis X & displayed value

Post by paradoxoff » Sat Sep 24, 2011 8:04 am

Code: Select all

((DateAxis)chart.getXYPlot().getDomainAxis()).setDateFormatOverride(new SimpleDateFormat("'Week' w"));

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

Re: rang Axis X & tickLabel

Post by BO » Tue Sep 27, 2011 11:13 am

hi paradoxoff
do you know why the format ww/yyyy of the date '01/01/2010' gave 53/2010 and not '53/2009' ?

Image

other problem
I don't know why I have the same values on DomaineAxis :
very strange :(

Code: Select all

org.jfree.data.time.RegularTimePeriod periodeTemp = org.jfree.data.time.RegularTimePeriod.createInstance(class org.jfree.data.time.Month, date_i, TimeZone.getDefault());
...
DateAxis dateaxis = (DateAxis)plot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));
Image

thanks
Last edited by BO on Wed Sep 28, 2011 7:03 am, edited 1 time in total.

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

Re: rang Axis X & tickLabel

Post by BO » Wed Sep 28, 2011 7:02 am

Image

I do it with following code:

Code: Select all

		if (periode_id.equals("month")) { // month
			dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat(pPERIODE_FORMAT1))); // Deprecated. As of version 1.0.13, use DateTickUnitType instead.
			dateaxis.setVerticalTickLabels(true);
		} else if (periode_id.equals("quarter")) { // // quarter of year
			String[] quarters={" 1.", " 2.", " 3.", " 4."};
			dateaxis.setDateFormatOverride(new QuarterDateFormat(TimeZone.getDefault(),quarters, true));
			dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 3, new SimpleDateFormat(pPERIODE_FORMAT1)));
		} else { // week
			dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat(pPERIODE_FORMAT1)));
			dateaxis.setVerticalTickLabels(true);
			/*PeriodAxis periodaxis =  new PeriodAxis("week");
			periodaxis.setMajorTickTimePeriodClass(jfreechartTimeClass);
			periodaxis.setMinorTickTimePeriodClass(jfreechartTimeClass);
	        PeriodAxisLabelInfo aperiodaxislabelinfo[] = new PeriodAxisLabelInfo[2];
			aperiodaxislabelinfo[0] = new PeriodAxisLabelInfo(jfreechartTimeClass, new SimpleDateFormat("w"));
	        aperiodaxislabelinfo[1] = new PeriodAxisLabelInfo(org.jfree.data.time.Year.class, new SimpleDateFormat("yyyy"));
	        periodaxis.setLabelInfo(aperiodaxislabelinfo);
			plot.setDomainAxis(periodaxis);*/
		}
I have to set tickLabel in vertical cause of space not enough

now I would like to show the 1srt unite of time (Quarter, Month, of Week) on the 1srt band and the YEAR on the 2snd one
I saw the PeriodAxisDemo1 using PeriodAxis but in my cas, I have to use DateAxis and not PeriodAxis (the RangeGridlines of 2 charts are differents)

Someone can help me?
thanks a lot
BO

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

Re: rang Axis X & tickLabel

Post by david.gilbert » Fri Sep 30, 2011 5:12 am

There is not an easy solution in JFreeChart for what you want to do. PeriodAxis was my previous attempt at getting something like this to work in a general way. I wasn't 100% happy with the result (it has a few quirks) but it was useful enough to release.
David Gilbert
JFreeChart Project Leader

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

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

Re: rang Axis X & tickLabel

Post by david.gilbert » Fri Sep 30, 2011 5:14 am

Oh, and that "53/2010" label looks like a bug for sure.
David Gilbert
JFreeChart Project Leader

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

Locked