Contents Previous Next

8.19.1 Standard two axis graphs

Assuming we start with the traditional two axis graph, one X and one Y axis. You may then change the position of each axis by calling Axis::SetPos($aPosition) You have to remember that you need to specify the position on the other axis. SO you need to specify the world-coordinate for the position. By default the axis are each positioned at the 0-point on the other axis, i.e. the axis will cross at the 0,0 point in the graph.

In addition to the standard positioning you may also use the two special position markers "min" and "max". This will position the axis at the minimum (or maximum) position of the other axis.

For example, to make sure that the X-axis is always at the bottom of the graph (at lowest possible Y-value) you would have to add the line

 $graph->xaxis->SetPos ("min");

To change the color and width of the axis you have to make use of the Axis::SetColor() and Axis::SetWeight() methods.


Invisible axis Even though JpGraph (1.7) doesn't directly support "hidden" axis where the labels are still drawn it is very easy to achieve this effect by setting the colors of the axis to be the same as the background. See the example barintex2.php in the Example directory. To completely hide an axis you can make use of the Hide()

You might also want to add titles to the axis. This is done through the Axis::SetTitle() method. This is actually just a shortcut for accessing the title property direct. Axis::title::Set() which also allow you to set the alignment in one call.

By default the position of the title is to the far right for the X-axis and in the middle (and 90 degrees rotated) for the Y-axis.

You can adjust the position of the title with the help of the second argument to the Axis::SetTitle() method.

The possible positions are "high","middle" and "low" which refers to the scale values on the axis.

One common modification you might want to do to the title is to increase the margin between the axis and the actual title. This is often necessary to do for the Y-axis if the values displayed are large. You may adjust the distance (in pixels) between the axis and the title by using the method Axis::SetTitleMargin()

So for example to increase the margin on the Y-axis you might add the line

 $graph->yaxis->SetTitleMargin(40 );

to your code.

Finally we mention something about the positioning of tick marks and labels on the axis. You have the possibility to choose what side of the axis the tick marks and the labels should be at. For the X-axis this can be specified as either on the the top (inside the plot area) or at bottom (outside of the plotarea). In the same way you can specify for the Y-axis if the labels ( or ticks) should be on the left or right side.

To adjust the label positioning you have to use the method Axis::SetTitleSide() and to adjust the position of the tick mark you have to use the method SetTickSide()

Note: There is also an alias for this method, SetTickDirection() which is deprecated from version 1.7 but kept for backwards compatibility.
Valid arguments for these methods are

For example, the following lines added to a script would change side of the labels and tickmarks for the X-axis.

 $graph->xaxis->SetLabelPos (SIDE_UP);
$graph->xaxis-> SetTickSide( SIDE_DOWN);

This technique is for example used if you position the X-axis at the top of the graph as the following example shows.



Figure 93: Example of both how to adjust the position of the X-axis as well as adjusting the side for the tick and axis title [src] 


Contents Previous Next