Starting X Axis with tick and negative value

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
pdvmipv
Posts: 13
Joined: Tue Mar 18, 2008 11:11 am

Starting X Axis with tick and negative value

Post by pdvmipv » Tue Mar 18, 2008 11:59 am

Problem Description
Xmin and max values :
scalaMinX= - 7207
scalaMaxX= 27506
dimX=10

I draw the axis using the following sequence
......
NumberAxis domainAxis_x = (NumberAxis) plot.getDomainAxis();
domainAxis_x.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
domainAxis_x.setRange(new Range(scalaMinX, scalaMaxX));
domainAxis_x.setFixedAutoRange(scalaMaxX - scalaMinX);
domainAxis_x.setAutoRangeIncludesZero(false);
domainAxis_x.setTickUnit(new NumberTickUnit((scalaMaxX - scalaMinX) / dimX));

The result is to have an axis with the first tick positioned not at the beginning of the axis with the value of -6942.6 but some pixel right.
It seems the jfreechart compute the delta tick starting from 0 (negative and positive) and not from the lower value.
What I want is to obtain a X axis with the first tick positioned at the beginning of the axis labeled with -7207 and the subsequents tick positioned at the delta value of ((scalaMaxX-scalaMinx)/dimX) .

How can I obtain that ?

Thanks in advance
[/img]

pdvmipv
Posts: 13
Joined: Tue Mar 18, 2008 11:11 am

Post by pdvmipv » Wed Mar 19, 2008 8:29 am

To be more clear
Xmax=27506
Xmin=-7207
Delta Tick=(27506+7207)/10=3471.3

I expected to obtain a graphics with the X scale drawed like the following:

0
!---------------!-------------!--------------!-------------!
-7207.......-3753.7.....-264.4........3206.9......6678.2

but I obtain the following with the an extra minor tick just few pixel
right the axis start.

0
!--!------------!-------------!--------------!-------------!
-6942.6....-3471.3.........0...........3471.3........6942.6

Why ?
It seems jfreechart compute the ticks starting from 0 (positive and negative). The value of 6942.6 is correct but the real min value of the
X axis is not printed. How can I obtain the scale as above with the axis
starting with ticks from the beginning of the axis (without the extra tick added just after the beginning) and with the effective min value of -7207 printed ?

Thanks

pdvmipv
Posts: 13
Joined: Tue Mar 18, 2008 11:11 am

Post by pdvmipv » Thu Mar 20, 2008 2:46 pm

Hi David, as nobody seems to have an answer to my probleme, I try to ask you directly if you can suggest me a way to perform what I am asking for. I am not asking a complete code listing but a suggestion to
resolve my needs.
Thanks

slaberer
Posts: 5
Joined: Sun Apr 20, 2008 4:51 pm

Post by slaberer » Tue May 13, 2008 9:07 am

I have got exactly the same problem. Did you by any chance find a solution for what you were looking for? I have been trying all sorts of variations and it always keeps putting the ticks around 0 and also displaying 0 which I really don't want.
David any chance you could give us a hint
Thanks
Sergio

RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

Post by RoyW » Tue May 13, 2008 8:08 pm

You could try creating your own number axis and overriding calculateLowestVisibleTickValue(). You will have to declare scalaMinX as final

Code: Select all

       NumberAxis     domainAxis_x = new NumberAxis("X Values"){
           protected double calculateLowestVisibleTickValue() {
               return scalaMinX;
           }
       };

    domainAxis_x.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 
    domainAxis_x.setRange(new Range(scalaMinX, scalaMaxX)); 
    domainAxis_x.setFixedAutoRange(scalaMaxX - scalaMinX); 
    domainAxis_x.setAutoRangeIncludesZero(false); 
    domainAxis_x.setTickUnit(new NumberTickUnit((scalaMaxX - scalaMinX) / dimX)); 

   plot.setDomainAxis(domainAxis_x);

The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site

slaberer
Posts: 5
Joined: Sun Apr 20, 2008 4:51 pm

Post by slaberer » Wed May 14, 2008 3:23 pm

Great!
Many thanks to you RoyW. It helped and is working now.

Locked