Class AxisPrototype
(Defined in: jpgraph.php : 3441)
 
 AxisPrototype 
 Hide() 
 HideFirstLastLabel() 
 HideFirstTickLabel() 
 HideLabels() 
 HideLastTickLabel() 
 HideLine() 
 HideTicks() 
 HideZeroLabel() 
 SetColor() 
 SetFont() 
 SetLabelAlign() 
 SetLabelAngle() 
 SetLabelFormat() 
 SetLabelFormatCallback() 
 SetLabelFormatString() 
 SetLabelMargin() 
 SetLabelSide() 
 SetMajTickPositions() 
 SetPos() 
 SetPosAbsDelta() 
 SetTextLabelInterval() 
 SetTextTickInterval() 
 SetTickLabels() 
 SetTickPositions() 
 SetTickSide() 
 SetTickSize() 
 SetTitle() 
 SetTitleMargin() 
 SetTitleSide() 
 SetWeight() 
 __construct() 
 

Class usage and Overview
The Axis class represents either the X or Y axis in a graph. This class is noramlly accessed through the instance variables graph->xaxis, $graph->yaxis, or $graph->y2axis Public properties:
Name Type Description
title Text Axis title text
scale LinearScale/LogScale Scale used for axis

 

See also related classes:
LinearScale, LogScale and Text

 


Class Methods

 

AxisPrototype ::
Hide($aHide)
Hide the axis

ArgumentDefaultDescription
$aHide true Flag.

Description:
This method is used to hide the axis. 

Example:

$graph->xaxis->Hide(); // Hide xaxis
$graph->yaxis->Hide(); // Hide y-axis

 

AxisPrototype ::
HideFirstLastLabel()
Hide the first and last label on the scale.


Description:
Hide the first and last label on the scale. Usefull whe you are using Axis Type of AXSTYLE_BOXIN or AXSTYLE_BOXOUT to avoid the labels to owerwrite a box around the plot. 
 
See also:

Example:

//...
$graph->SetAxisStyle(AXSTYLE_BOXOUT);
$graph->SetBox();
$graph->xaxis->HideFirstLastLabel();
$graph->yaxis->HideFirstLastLabel();
//...

 

AxisPrototype ::
HideFirstTickLabel($aShow)
Hide the first label

ArgumentDefaultDescription
$aShow false Flag.

Description:
Calling this method will hide the first label on the axis. This is usefull when the y axis have negative values and a value on the x-axis would be partially obscured by the values on the y-axis. This gets automatically called in this case.

This is probably of less use for the end user of the library. 

Example:

$graph->xaxis->HideFirstTicklabel()

 

AxisPrototype ::
HideLabels($aHide)
Hide all labels on the axis

ArgumentDefaultDescription
$aHide true true=Hide all labels

Description:
Hide all labels on the axis but keep tick marks and axis line. 
 
See also:

Example:

$graph->xaxis->HideLabels()

 

AxisPrototype ::
HideLastTickLabel($aShow)
Hide the last tick label on the axis.

ArgumentDefaultDescription
$aShow false Flag

Description:
The mirror of HideFirstTickLabel() 
 
See also:

Example:

$graph->xaxis->HideLastTickLabel();

 

AxisPrototype ::
HideLine($aHide)
// Hide the actual axis-line, but still print the labels

ArgumentDefaultDescription
$aHide true True=Hide axis line

Description:
Hide the line of the axis. This only hides the axis-line but will keep the tick marks and labels. If you want to hide the tick marks you should call HideTicks(). To hide the axis completely, line, ticks and labels use Hide(). 
 
See also:

Example:

// Hide line and tick marks
$graph->yaxis->HideLine();
$graph->yaxis->HideTicks();

 

AxisPrototype ::
HideTicks($aHideMinor, $aHideMajor)
Hide minor or major tick marks.

ArgumentDefaultDescription
$aHideMinor true True = Hide minor tick marks
$aHideMajor true True = Hide major tick marks

Description:
Hide major or minor tick makrs on the axis. 

Example:

// Only display major tick marks
$graph->yaxis->HideTicks(true,false);

 

AxisPrototype ::
HideZeroLabel($aFlag)
Hide zero label

ArgumentDefaultDescription
$aFlag true Flag.

Description:
Hide the zero label. Usefull if the axis cross at zero and the label would owerwrite the other axis scale.  
 
See also:

Example:

$graph->yaxis->HideZeroLabel();

 

AxisPrototype ::
SetColor($aColor, $aLabelColor)
Specify color of Axis and it's labels

ArgumentDefaultDescription
$aColor  Color for axis
$aLabelColor false Color for labels on axis

Description:
Specifies the color of the axis line as well as the labels on the axis. If the label color is not specified it will be the same as the axis color. 

Example:

$graph->xaxis->SetColor('blue');
$graph->yaxis->SetColor('blue','black');

 

AxisPrototype ::
SetFont($aFamily, $aStyle, $aSize)
Set the font for labels on the axis

ArgumentDefaultDescription
$aFamily  Font family
$aStyle FS_NORMAL Font style
$aSize 10 Font size

Description:
Specify font for labels on axis. Please note that if you need labels to be rotated an angle other than 0 or 90 you must use TTF fonts and not the builtin fonts (i.e. FF_FONT1, FF_FONT2, FF_FONT3)  
 
See also:

Example:

$graph->xaxis->SetFont(FF_ARIAL);

 

AxisPrototype ::
SetLabelAlign($aHAlign, $aVAlign, $aParagraphAlign)
Specify horizontal and vertical alignment for labels

ArgumentDefaultDescription
$aHAlign  Horizontal alignment
$aVAlign 'top' Vertical alignment
$aParagraphAlign 'left' paragraph align for multi-line texts

Description:
Specifies the horizontal and vertical alignment for the labels on the axis. The alignment specifies how the labels is adjusted relative to the tickmark.

Note that this is handled automatically but on some occasion there is a genuine need to override the automtic values. For example if the graph is rotated it might be necessary to adjust the alignment to get a visual acceptable label alignment.

Possible horizontal alignment are: 'left', 'center', 'right'
Possible vertical alignment are: 'top', 'center', 'bottom'

See horizbarex1.php, horizbarex2.php for real life examples.  

Example:

$graph->xaxis->SetLabelAlign('right','center');

 

AxisPrototype ::
SetLabelAngle($aAngle)
Specify the angle for the tick labels

ArgumentDefaultDescription
$aAngle  Angle in degrees

Description:
Specify the rotation angle for the labels on the axis.

Note:
If you want to use any angles other than 0 and 90 degrees you must make sure that the labels are using TTF fonts. Internal fonts only support vertical and horizontal angles. 
 

See also:

Example:

$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,11);
$graph->xaxis->SetLabelAngle(45); // 45 degrees angle

 

AxisPrototype ::
SetLabelFormat($aFormStr)
Specify printf() format string for labels

ArgumentDefaultDescription
$aFormStr  Format string

Description:
Specify a printf() format string for the axis labels. if you need more advanced control of the formatting you can install a label format callbacl routine with Axis::SetLabelFormatCallback() 
 
See also:

Example:

$graph->xaxis->SetLabelFormat('%0.1f%%');

 

AxisPrototype ::
SetLabelFormatCallback($aFuncName)
Specify callback function for labels on axis

ArgumentDefaultDescription
$aFuncName  Callback function

Description:
This can be used when more advance formatting of the axis labels are required. For example this could be used to format numbers with space or commas betwen the '1000.

The callback routine is called with one argument, the current number to be displayed and should return the number to be displayed.

For simple formatting use SetlabelFormat() to specify a printf() style formatting string.

The callback function specified should can either be a global function or a class method, for example

$SomeClass = new SomeClass(...); 
... 
$g->SetXLabelFormatCallback(array($SomeClass,'xLabelCallback'));

There is, however, one caution. Any $this data used within LabelFormatCallbackInDerivedClass MUST BE SET BEFORE SetLabelFormatCallback is invoked! it appears that $this is bound/copied when SetLabelFormatCallback is invoked. Only $this data defined at that time is available within the callback function! Likewise, modifications to $this data AFTER SetLabelFormatCallback have no effect since the $this object used by the callback function has already been bound/copied.

The same issues obtain when the callback function is in a seperate class!

For a full example see barscalecallbackex1.php  
 

See also:

Example:

function yLabelFormat($aLabel) {
    
// Format '1000 english style
    
return number_format($aLabel)
    
// Format '1000 french style
    // return number_format($aLabel, 2, ',', ' ');
}

$graph->yaxis->SetLabelFormatCallback('yLabelFormat');


 

AxisPrototype ::
SetLabelFormatString($aFormStr, $aDate)
Specify a printf()-style format string for labels.

ArgumentDefaultDescription
$aFormStr  Format string
$aDate false No description available

Description:
Synonym for SetLabelFormat(). Will be deprecated in a future release. Use SetLabelFormat() instead. 
 
See also:

Example:

$graph->xaxis->SetLabelFormatString('%0.1f%%');

 

AxisPrototype ::
SetLabelMargin($aMargin)
Specify margin between labels and tick marks

ArgumentDefaultDescription
$aMargin  Margin in pixels

Description:
Specify margin between labels and tick marks. 

Example:

$graph->xaxis->SetLabelMargin(15);

 

AxisPrototype ::
SetLabelSide($aSidePos)
Specify what side of the axis labels should be on.

ArgumentDefaultDescription
$aSidePos  Which side of the axis the labels should be on

Description:
Specify which side the labels should go on. For horizontal axis valid arguments are SIDE_UP, SIDE_DOWN and for vertical axis it is SIDE_LEFT, SIDE_RIGHT.

See topaxisex1.php for an example when this is usefull.

Note: Synonym to SetLabelPos()  
 

See also:

Example:

$graph->xaxis->SetLabelSide(SIDE_UP);

 

AxisPrototype ::
SetMajTickPositions($aMajPos, $aLabels)
// Manually specify major tick positions and optional labels

ArgumentDefaultDescription
$aMajPos  No description available
$aLabels NULL No description available

Description:
No description available.

 

AxisPrototype ::
SetPos($aPosOnOtherScale)
Position for axis line on the "other" scale

ArgumentDefaultDescription
$aPosOnOtherScale  Position in world-coordinate

Description:
Specifies the position of the axis on the other axis. This can be specified as either a numeric value (which gives the absolute position on the other scale). OIt can also be specified as a string value as either 'min' or 'max' which sould position the axis either at the beginning or the end of the opposite axis scale.

See topaxisex1.php for a real life example. 

Example:

$graph->xaxis->SetPos('max'); // Locate x-axis at the top

 

AxisPrototype ::
SetPosAbsDelta($aDelta)
Position the multiple Y-axis

ArgumentDefaultDescription
$aDelta  Delta in pixels

Description:
Set the position of the Y-axis to be X-pixels delta to the right of the max X-position (used to position the multiple Y-axis) 

 

AxisPrototype ::
SetTextLabelInterval($aStep)
Specify interval for for test labels

ArgumentDefaultDescription
$aStep  Intervall

Description:
Specify that every $step tick mark should have a label  
 
See also:

Example:

// Only draw labels on every 2nd tick mark
$graph->xaxis->SetTextLabelInterval(2);

 

AxisPrototype ::
SetTextTickInterval($aStep, $aStart)
Specify what ticks should be displayed

ArgumentDefaultDescription
$aStep  Intervall between ticks
$aStart 0 Start tick

Description:
Specify that every $step of the ticks should be displayed starting at $start.  
 
See also:

Example:

$graph->xaxis->SetTextTickInterval(1,2);

 

AxisPrototype ::
SetTickLabels($aLabelArray, $aLabelColorArray)
Specify text labels for the ticks. One label for each data point

ArgumentDefaultDescription
$aLabelArray  Array with labels
$aLabelColorArray null Individual colors for each label

Description:
Specify the labels for a text axis. This is used to manually set labels for the x-axis when a text scale has been specified.

If fewer labels than data points are specified then the missing labels will be set to the data points ordinal numbers.

The color argment is an array that can be used to specify individual colors for each of the labels. If fewer colors than labels are specified then the colors will wrap around.  
 

See also:

Example:

// Set the x-axel to the month of the years using the
// gloablly available $gDateLocale

$a $gDateLocale->GetShortMonth();
$graph->xaxis->SetTickLabels($a);
$graph->xaxis->SetFont(FF_FONT2);

 

AxisPrototype ::
SetTickPositions($aMajPos, $aMinPos, $aLabels)
// Manually specify the major and (optional) minor tick position and labels

ArgumentDefaultDescription
$aMajPos  No description available
$aMinPos NULL No description available
$aLabels NULL No description available

Description:
No description available.

 

AxisPrototype ::
SetTickSide($aDir)
Specify what side of the axis the ticks should be at

ArgumentDefaultDescription
$aDir  Specify side

Description:
Specify which side of the axis the tick marks should be on. Valid positions for a horizontal axis are SIDE_TOP, SIDE_BOTTOM and for verticla axis SIDE_LEFT and SIDE_RIGHT.

This is a shortform for accessing the tick method directly via the scale in the axis.

See topaxisex1.php for real life example.  
 

See also:

Example:

$graph->xaxis->SetTickSide(SIDE_TOP);

 

AxisPrototype ::
SetTickSize($aMajSize, $aMinSize)

ArgumentDefaultDescription
$aMajSize  No description available
$aMinSize 3 No description available

Description:
No description available.

 

AxisPrototype ::
SetTitle($aTitle, $aAdjustAlign)
Title for axis

ArgumentDefaultDescription
$aTitle  Title string
$aAdjustAlign 'high' Alignment of title along the axis

Description:
Set the title for the axis. You can specify the alignment as being either "high", "middle" and "low". To adjust the titles font and color you have to access the label instance variable. For example, $graph->xaxis->title->SetFont(FF_FONT2,FS_BOLD) 

Example:

$graph->xaxis->SetTitle('Values for 2002','middle');

 

AxisPrototype ::
SetTitleMargin($aMargin)
Specify distance from the axis

ArgumentDefaultDescription
$aMargin  Margin in pixels

Description:
Specify the distance between the axis and the title. 
 
See also:

Example:

$graph->xaxis->SetTitlemargin(50);

 

AxisPrototype ::
SetTitleSide($aSideOfAxis)
Specify what side of the axis the title should be at

ArgumentDefaultDescription
$aSideOfAxis  Side

Description:
For horizontal axis the side can be either SIDE_TOP or SIDE_BOTTOM and for vertical axis the position can be either SIDE_LEF or SIDE_RIGHT.

By default x-axis have the title below the axis and y-axis have it on the left and y2 on the right.

See topaxisex1.php for real life example 
 

See also:

Example:

$graph->xaxis->SetTitleSide(SIDE_TOP);

 

AxisPrototype ::
SetWeight($aWeight)
Weight of axis

ArgumentDefaultDescription
$aWeight  Weight in pixels

Description:
Specify the thickness of the axis in pixels 

Example:

$graph->xaxis->SetWeight(3);

 

AxisPrototype ::
__construct($img, $aScale, $color, , )
// should be labeled.

ArgumentDefaultDescription
$img  No description available
$aScale  No description available
$color  No description available
 No description available
array(0,0,0) No description available

Description:
No description available.