Number of ticks between upper & lower ranges...

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
aselaneli
Posts: 6
Joined: Wed Dec 21, 2011 11:09 am
antibot: No, of course not.
Location: Colombo

Number of ticks between upper & lower ranges...

Post by aselaneli » Mon Jan 02, 2012 11:22 am

Hi all,

I need to get the number of ticks between the upper & lower ranges of an axis.

Lets say that my lower range is 0 & the upper range is 100.
And the values are shown in gaps of 5. So when I ask for the number of tick count, it should return 21 (including 0 & 100)
Is there a method which serves this purpose..?? [something like myAxis.getTickCount()..??]
I tried tick related methods mentioned in http://www.jfree.org/jfreechart/api/jav ... rAxis.html
and http://www.jfree.org/jfreechart/api/gjd ... eAxis.html but no luck.

Any help is greatly appreciated. Thanks in advance.

Regards,
Asela.

azrael
Posts: 9
Joined: Fri Jan 20, 2012 1:02 pm
antibot: No, of course not.
Location: Germany

Re: Number of ticks between upper & lower ranges...

Post by azrael » Wed Jan 25, 2012 5:35 pm

needed the same.. found following solution, that works fine for me:

Code: Select all

	public static int calculateVisibleTickCount(NumberAxis axis) {

		double unit = axis.getTickUnit().getSize();
		Range range = axis.getRange();
		return (int) (Math.floor(range.getUpperBound() / unit) - Math.ceil(range.getLowerBound() / unit) + 1);

	}

hope it works for you as well...

Locked