Contents Previous Next

7.8 Specifying the scale manually

Normally the automatic scaling should be doing an adequate job in most circumstances but there might be cases where you like to manually set the scale. For example if you have several graphs where you like to be able to easily compare them and therefore want them all to have the same scale.

To specify a manual scale you have to add arguments to the standard Graph::SetScale() method. So to specify that you want an Y-scale between 0 and 100 you need to write

 $graph-> SetScale( "textlin",0,100 );

When you specify a scale manually there is one additional thing you need to decide. How the tick marks should be positioned. You have three choices

  1. Let JpGraph decide suitable tick marks honoring the exact scale you specified. This is the default behavior if you don't do anything else.
  2. Allow JpGraph to slightly adjust your specified min and max values. With the default method, depending on the min and max values, the end and start of the scale might not fall on an exact tick mark. For esthetic reasons you might still want the last/first tick mark to fall on the edges of the scale. By calling LinearScale::SetAutoTicks() you tell JpGraph to make the smallest necessary adjustment of the end/start points so that they fall on an exact tick mark.
  3. Manually specify the tick marks with a call to LinearTicks::Set() For example
     $graph->SetScale( "textlin",0,100 );
    $graph->yscale-> ticks->Set(10 ,5);

    Will set the major tick marks every at 0,10,20,.. And every minor tick mark in between (0,5,10,15,20,25,...).

The three images below illustrates the difference between the possibilities of ticks for a manual scale.



Figure 76: Manual scale, manual ticks major=7 minor=2 [src] 



Figure 77: Manual scale, automatic ticks with exact limits [src] 



Figure 78: Manual scale, automatic ticks where we allow adjustments of the limits [src] 


Contents Previous Next