Class Graph
(Defined in: jpgraph.php : 491)

Graph

Add()
AddBand()
AddLine()
AddText()
AddY()
AddY2()
CheckCSIMCache()
GetCSIMImgHTML()
GetHTMLImageMap()
Set3DPerspective()
Set90AndMargin()
SetAlphaBlending()
SetAngle()
SetAxisLabelBackground()
SetAxisStyle()
SetBackgroundCFlag()
SetBackgroundCountryFlag()
SetBackgroundGradient()
SetBackgroundImage()
SetBackgroundImageMix()
SetBackgroundImagePos()
SetBox()
SetClipping()
SetColor()
SetCSIMImgAlt()
SetFrame()
SetFrameBevel()
SetGridDepth()
SetIconDepth()
SetImgFormat()
SetMargin()
SetMarginColor()
SetScale()
SetShadow()
SetTextScaleAbsCenterOff()
SetTickDensity()
SetTitleBackground()
SetTitleBackgroundFillStyle()
SetUserFont()
SetUserFont1()
SetUserFont2()
SetUserFont3()
SetY2OrderBack()
SetY2Scale()
SetYDeltaDist()
SetYScale()
Stroke()
StrokeCSIM()
StrokeCSIMImage()
StrokeFrameBackground()
StrokeStore()
__construct()

Class usage and Overview
The Graph class is the main container class for all x,y-axis based plots which controls the creation of the entire graph. You must always instantiate one instance to create a graph. Through this class one controls many overall settings of the image displayed.

Please note that to create Pie, Gantt, Canvas and Spider charts you have to use their respective creation classes.

Public properties:

Name | Type | Description
--- | --- | ---
xaxis | Axis | X-axis
yaxis | Axis | Y-axis
xgrid | Grid | Grid lines for X-axis
ygrid | Grid | Grid lines for Y-axis
legend | Legend | Properties for legend box
title | Text | Graph main title
subtitle | Text | Sub title
subsubtitle | Text | Sub title
tabtitle | GraphTabTitle | Option Tab title for graph
img | RotImage | The image canvas

See also related classes:
Axis, Grid, Text and Image

Class Methods

Graph ::
Add($aPlot)
Add any plot object to the graph

Argument | Default | Description
--- | --- | ---
$aPlot |  | No description available

Description:
Each plot that should be displayed within the graph has to be added to the graph. This is the main method to add object. You can use this method to add

- Plots
- Texts
- Plot lines
- Plot bands

This method will add a plopt for use with the ?Left? Y-scale, (the normal Y scale). To add a plot to the second Y scale you should use AddY2().

Note that since the plot is added as a reference any changes you make to the original plot will also happen to the plot you have added to the graph.

Add() will always add plots to the first Y-scale. If you are using two Y-axis then you must use AddY2() to add plots to the second Y-scale.

See also:

- Graph::AddY2()
- Graph::SetScale()

Example:

$graph = new Graph(300,200,"auto");
$graph->img->SetMargin(40,30,20,40);
$graph->SetScale("textlin");
$graph->SetShadow();
// Create a bar pot
$bplot = new BarPlot($datay);
$bplot->SetFillColor("orange");
$graph->Add($bplot);
// Display the graph
$graph->Stroke();

Graph ::
AddBand($aBand, $aToY2)
Add vertical or horizontal band

Argument | Default | Description
--- | --- | ---
$aBand |  | No description available
$aToY2 | false | Add object to Y2 axis

Description:
A plot may have one or several filled horizontal or vertical "bands" to emphasise certain scale areas.

Each band is an instance of the PlotBand class. For types of plot band see the documentation of class PlotBand

Note: You can alos use the standard method Add() to add bands.

See also:

- PlotBand::__construct()
- Graph::Add()

Example:

$graph->AddBand(new PlotBand(HORIZONTAL,BAND_RDIAG,0, "max", "red", 2));

Graph ::
AddLine($aLine, $aToY2)
Add a line object (class PlotLine) to the graph

Argument | Default | Description
--- | --- | ---
$aLine |  | No description available
$aToY2 | false | Add line to Y2 axis

Description:
Add a vertical or horizontal line to the graph. The line will extend over the entire length of the plot. The plot object is an instance of the PlotLine class

Note: You can alos use the standard method Add() to add lines.

See also:

- PlotLine::__construct()
- Graph::Add()

Example:

// Add mark graph with static lines
$graph->AddLine(new PlotLine(HORIZONTAL,0,"black",2));
$graph->AddLine(new PlotLine(VERTICAL,3,"black",2));

Graph ::
AddText($aTxt, $aToY2)
Add text object to the graph

Argument | Default | Description
--- | --- | ---
$aTxt |  | No description available
$aToY2 | false | Add text to Y2 axis

Description:
Adds an instance of the Text class to the graph, allowing arbitrary text to be placed anywhere in the graph.

Note: You can alos use the standard method Add() to add bands.

See also:

- Text::__construct()
- Graph::Add()

Example:

// You can specify the position as fraction of the
// image width and height
$caption=new Text(? Figure 1. Temperature over time?,0.1,0.8);
$caption->SetFont(FONT1_BOLD);
$graph->AddText($caption);

Graph ::
AddY($aN, $aPlot)
Add plot to second Y-axis n

Argument | Default | Description
--- | --- | ---
$aN |  | Number of axis to add data to
$aPlot |  | No description available

Description:
This method is used to add a plot in the case the graph has multiple Y-axis. The first argument should be the index of the Y-axis.

Example:

<? php
include ("../jpgraph.php");
include ("../jpgraph_line.php");
$datay = array(5,3,7,2);
$datay2 = array(88,10,55,42);
$datay3 = array(255,35,745,244);
$datay4 = array(130,97,68,119);
// Setup the graph
$graph = new Graph(600,250);
$graph->SetMargin(30,200,20,20);
$graph->SetMarginColor('white');
$graph->SetColor('lightgray');
$graph->SetScale("intlin");
$graph->SetYScale(0,"lin");
$graph->SetYScale(1,"lin");
$graph->SetYScale(2,"lin");
$p1 = new LinePlot($datay);
$p1->SetColor('blue');
$graph->Add($p1);
$p2 = new LinePlot($datay2);
$p2->SetColor('darkred');
$graph->AddY(0,$p2);
$graph->ynaxis[0]->SetColor('darkred');
$p3 = new LinePlot($datay3);
$p3->SetColor('red');
$graph->AddY(1,$p3);
$graph->ynaxis[1]->SetColor('red');
$p4 = new LinePlot($datay4);
$p4->SetColor('blue');
$graph->AddY(2,$p4);
$graph->ynaxis[2]->SetColor('blue');
// Output line
$graph->Stroke();

Graph ::
AddY2($aPlot)
Add plot to second Y-axis

Argument | Default | Description
--- | --- | ---
$aPlot |  | No description available

Description:
Works the same way as Add() but the plot is added for use with the Y2 scale (the right Y scale) instead.
See also:

- Graph::Add()
- Graph::SetY2Scale()

Example:

$graph = new Graph(300,200);
$graph->SetScale('linlin');
$graph->SetY2Scale('linlog');
$lineplot = new LinePlot($datay);
$graph->AddY2($lineplot);

Graph ::
CheckCSIMCache($aCacheName, $aTimeOut)
Check if cached CSIM graph exists

Argument | Default | Description
--- | --- | ---
$aCacheName |  | Cache file name
$aTimeOut | 60 | Timeout (in minutes)

Description:
This method is used to enable caching for graphs that use image maps (CSIM). It should be called as the first method after the creation of the Graph(). If the cached image and image map exists this will be directly sent back to the browser and script execution will stop.

This specifically means that no lines of code after this method will be executed in case the image/map is found in the cache.

See also:

- Graph::StrokeCSIM()

Example:

$graph = Graph(300,200);
$graph->CheckCSIMCache('myimage01',10);
// .. Lopt of code to create the image
$graph->StrokeCSIM();

Graph ::
GetCSIMImgHTML($aCSIMName, $aScriptName, $aBorder)

Argument | Default | Description
--- | --- | ---
$aCSIMName |  | No description available
$aScriptName | 'auto' | No description available
$aBorder | 0 | No description available

Description:
No description available.

Graph ::
GetHTMLImageMap($aMapName)
Get a complete .. tag for the final image map

Argument | Default | Description
--- | --- | ---
$aMapName |  | Image map name

Description:
When you are using image maps for a plot then this routine is called in your script to get the resulting image map as a string for the graph. The image map is given the name specified as the first argument to the method.

Please note that due to the way client side image maps work you need to have both the image map and the image available in the script that is sent back to the browser. Since you can't do this at the same time you will have to create an image to disk and read the image map. The you have to stream the HTML page with an tag to load the previously generated image as well as the image map.

Example:

// The image must be stroked to find out the image maps
$graph->Stroke($myfile);
// Then read the image map
$imagemap = $graph->GetHTMLImageMap('MainMap');
echo $imagemap;
echo "<img src=$myfile>";

Graph ::
Set3DPerspective($aDir, $aHorizon, $aSkewDist, $aQuality, $aFillColor, $aBorder, $aMinSize, $aHorizonPos)
Enable image perspective transformation

Argument | Default | Description
--- | --- | ---
$aDir | 1 | Direction for 3D perspective
$aHorizon | 100 | Distance (in pixels) from the bottom of the image to the horizon
$aSkewDist | 120 | Skew distance (in pixels) on the horizon
$aQuality | false | Boolean. High quality =
$aFillColor | '#FFFFFF' | What fill color to use
$aBorder | false | Boolean. Border around?
$aMinSize | true | Boolean. Make the transformed image canvas as small as possible
$aHorizonPos | 0.5 | Distance from left on the horizon for the point of focus

Description:
Enable final image perspective transformation before sending the image back to the browser. This makes a "skewing" tansformation of the image to emulate a 3D depth.

Allowed argument for $aDir are

1. 'SKEW3D_UP'
2. 'SKEW3D_DOWN'
3. 'SKEW3D_LEFT'
4. 'SKEW3D_RIGHT'

$aHorizon Determines how far away the horizon are from the bottom of the picture (in pixels)

aSkewDist How far to the right on the horizon is the "skewing point", a large value gives a very strong for-shortening.

aQuality Use high quality (takes longer time) TRUE or FALSE

aFIllColor Fill background color in the image on places where the original image no longer cover the entire canvas.

aBorder Border around or not

aMinSize Just make the image as large as it has to be. TRUE or FALSE. If this argument is set to false then the original image size will be preserved.

aHorizonPosHow far, in fraction, should the point of focus be from the left edge of the image.

Example:

$graph->Set3DPerspective(SKEW3D_UP,100,120,true);

Graph ::
Set90AndMargin($lm, $rm, $tm, $bm)
Rotate the graph 90 degrees and set the margins

Argument | Default | Description
--- | --- | ---
$lm | 0 | Left margin
$rm | 0 | Right Margin
$tm | 0 | Top margin
$bm | 0 | Bottom margin

Description:
Rotates the graph 90 degrees and sets the margin as specified.

Remember that when rotating the graph it might be a good idea to adjust the axis so that the alignment of the labels for x and Y axis. For example by setting them as:

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

Note: This is slightly different from using SetAngle() and SetMargin() in that this method automatically adjusts the margin so that width becomes height and vice versa due to the rotation.

See also:

- Graph::SetAngle()
- Graph::SetMargin()

Example:

$graph = new Graph(300,200,"auto");
$graph->SetScale('linlin');
$graph->Set90AndMargin(40,40,40,40);
$graph->SetShadow();
$graph->title->Set("A 90 degrees rotated scatter plot");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
// Adjust the label align for X-axis so they look good rotated
$graph->xaxis->SetLabelAlign('right','center','right');
// Adjust the label align for Y-axis so they look good rotated
$graph->yaxis->SetLabelAlign('center','bottom');
$sp1 = new ScatterPlot($datay,$datax);
$sp1->mark->SetType(MARK_FILLEDCIRCLE);
$sp1->mark->SetFillColor("red");
$sp1->mark->SetWidth(5);
$graph->Add($sp1);
$graph->Stroke();

Graph ::
SetAlphaBlending($aFlg)
Eanble/disable alpha blending

Argument | Default | Description
--- | --- | ---
$aFlg | true | TRUE=Enable alpha blending

Description:
Enable disable alpha blending. The transparency factor is specified in the color as transparency fraction. For example, to specify a red color which is 50% transparent you specify this as:

"red@0.5" (or "#FF0000@0.5")

can then use this color specification in all places where the color may be specified. If the alpha blending is not active then the alpha parameter will have no effect.

Note that the use of alpha blending requires GD 2.01 or higher. By default alpha blending is enabled.

Example:

$graph->SetAlphaBlending();

Graph ::
SetAngle($aAngle)
Specify graph angle 0-360 degrees.

Argument | Default | Description
--- | --- | ---
$aAngle |  | Rotation angle for graph

Description:
The graph can be rotated an arbitrary number of degrees. This will allow you to easily create, for example, horizontal bar graphs by rotating a normal bar graph 90 degrees.

See horizbarex1.php for a real life example.

Note: If you want a 90 degrees rotated graph consider using Graph::Set90AndMargin() which greatly simplifies this with just one call

See also:

- Graph::Set90AndMargin()

Example:

$graph = new Graph(300,200);
$graph->SetScale('textlin');
$graph->SetAngle(90);

Graph ::
SetAxisLabelBackground($aType, $aXFColor, $aXColor, $aYFColor, $aYColor)
// Finally stream the generated picture

Argument | Default | Description
--- | --- | ---
$aType |  | No description available
$aXFColor | 'lightgray' | No description available
$aXColor | 'black' | No description available
$aYFColor | 'lightgray' | No description available
$aYColor | 'black' | No description available

Description:
No description available.

Graph ::
SetAxisStyle($aStyle)
Specify axis style (boxed or single)

Argument | Default | Description
--- | --- | ---
$aStyle |  | Style of axis

Description:
The most common type of axis is two axis which crosses at a specified point. However for scientific plot it is often common to want to mirror the axis (and the scale) around the plot area. This method controls which type to use

- AXSTYLE_SIMPLE, a simple two axis plots (default)
- AXSTYLE_BOXIN, axis around the plot area with the tick marks directed inside the plot area.
- AXSTYLE_BOXOUT, axis around the plot area with the tick marks directed outside of the plot area

See funcex1.php, funcex2.php and funcex3.php for real life examples.

Example:

$graph->SetAxisStyle(AXSTYLE_BOXIN);

Graph ::
SetBackgroundCFlag($aName, $aBgType, $aMix)
Set a country flag in the background

Argument | Default | Description
--- | --- | ---
$aName |  | Index or (partial) name of Country
$aBgType | BGIMG_FILLPLOT | Background fill type
$aMix | 100 | Mix percentage

Description:
[Synonym for SetBackgroundCountryFlag() ) Set a country flag in the background. All supported countries can be specified by either

1. Numeric index, (0-238)
2. Full or partial name, e.g. "norway"
3. The unique string index for the country

For a list of all available flags please run the file "listallflags.php" in the Example directory.

The final arcgument "aMix" is a value between 0-100 and specifies the blend factor for the flag.

Graph ::
SetBackgroundCountryFlag($aName, $aBgType, $aMix)
Set a country flag in the graph background

Argument | Default | Description
--- | --- | ---
$aName |  | Full or partial country name
$aBgType | BGIMG_FILLPLOT | Normal background fill type
$aMix | 100 | Mix fraction

Description:
Set a country flag in the background. All supported countries can be specified by either

1. Numeric index, (0-238)
2. Full or partial name, e.g. "norway"
3. The unique string index for the country

For a list of all available flags please run the file "listallflags.php" in the Example directory.

The final arcgument "aMix" is a value between 0-100 and specifies the blend factor for the flag.

Graph ::
SetBackgroundGradient($aFrom, $aTo, $aGradType, $aStyle)
Set a color gradient as the background

Argument | Default | Description
--- | --- | ---
$aFrom | 'navy' | Color 1
$aTo | 'silver' | Color 2
$aGradType | 2 | Gradient type
$aStyle | BGRAD_FRAME | Gardient layout style

Description:
This method allows you to specify a color gradient as the background of the graph. The color gradient can either fill the entire graph, just the plopt area or just the margin. This is specified by the $aStyle argument by specifyin one of the following values:

- BGRAD_FRAME, Fill the entire graph with the gradient
- BGRAD_PLOT, Just fill the plot area
- BGRAD_MARGIN, Just the margin

The gradient type can be one of

- GRAD_VER, Vertical gradient
- GRAD_HOR, Horizontal gradient
- GRAD_MIDHOR, From the center and out, horizontal
- GRAD_MIDVER, From the center and out, vertical
- GRAD_WIDE_MIDVER, From the center and out, vertical. Wide mid section.
- GRAD_WIDE_MIDHOR, From the center and out, horizontal. Wide mid section.
- GRAD_CENTER, From the center and beaming out
- GRAD_LEFT_REFLECTION, Simulates a reflection on the left side
- GRAD_RIGHT_REFLECTION, Simulates a reflection on the right side

Note: In order for the gradient to be visible the Frame must be enabled, i.e. graph->ShowFrame(false) will hide the gradient. If you like to hide the frame around the entire graph set the color to the margin color or set the weight of the frame line to 0.
See also:

- Graph::SetBackgroundImage()
- Graph::SetFrame()

Example:

$graph->SetBackgroundGradient('blue','navy:0.5',GRAD_HOR,BGRAD_MARGIN);

Graph ::
SetBackgroundImage($aFileName, $aBgType, $aImgFormat)
Specify a background image fro the plot

Argument | Default | Description
--- | --- | ---
$aFileName |  | Filename for background image
$aBgType | BGIMG_FILLPLOT | Style of background image
$aImgFormat | 'auto' | Image format ("jpeg", "gif", "png")

Description:
A graph may have a background image. The image is loaded from a specified file and may be of type GIF, JPG or PNG. The image type may also be specified as "auto", in this case the image format is determined by the file ending.

The positioning and sizing of the background image can be controlled by the $aBgType parameter. Possible values are

- BGIMG_FILLPLOT, Adjust the size of the image to just fit the plotarea
- BGIMG_FILLFRAME, ADjust the size of the image to just fit the entire graph area
- BGIMG_COPY, Just copy the image as is to upper left corner
- BGIMG_CENTER, Just copy the image but center it.

If you want ot use a background image on a canvas graph you must be carefull. Since canvas graph use no buffering, i.e everythng is written directly in the order you specify the commands. For canvas graph the background image get's stroked when you call the Initframe() method. SO, this call should eb among the very first. Every graph object after that will be stroked on top of the specified background image.
See also:

- Graph::SetBackgroundGradient()

Example:

//
$graph->SetBackgroundImage("tiger_bkg.png",BGIMG_FILLFRAME);
// If you use a canvas graph, and only canvas graphs,
// you must manually call the InitFrame() method.
$graph->InitFrame();

Graph ::
SetBackgroundImageMix($aMix)
Specifes what how much the background image should be blendid in with the background

Argument | Default | Description
--- | --- | ---
$aMix |  | Mix value (0-100)

Description:
Specifes what how much the background image should be blendid in with the background.

Graph ::
SetBackgroundImagePos($aXpos, $aYpos)
// Adjust background image position

Argument | Default | Description
--- | --- | ---
$aXpos |  | No description available
$aYpos |  | No description available

Description:
No description available.

Graph ::
SetBox($aDrawPlotFrame, $aPlotFrameColor, $aPlotFrameWeight)
Set a frame around the plot area

Argument | Default | Description
--- | --- | ---
$aDrawPlotFrame | true | True=Draw the frame
$aPlotFrameColor | array(0,0,0) | Frame color
$aPlotFrameWeight | 1 | Width fo frame line

Description:
This is used to specify whether the plot-area should have a rectangle around it and the specifics of that rectangle.
See also:

- Graph::SetFrame()

Example:

$graph = new Graph(300,200);
$graph->SetScale('linlin');
$graph->Box();

Graph ::
SetClipping($aFlg)
Enable clipping of graph outside the plotarea

Argument | Default | Description
--- | --- | ---
$aFlg | true | Enable/disbale clipping

Description:
Enable or disable clipping outside the plot area. If clipping is enabled then only the part of the graph exactly inside the plot area will be visible.

Clipping may come in handy when you for example set a manual scale and have data points outside the specified range.

By default clipping is disabled.

Note 1: Clipping is only supported for graphs at 0 or 90 degrees rotation and will generate an error message if enabled together with any other angle.

Note 2: The clipping is implemented with a O(1) algorithm in terns of data size.

Example:

$graph->SetClipping();

Graph ::
SetColor($aColor)
Specify color for the plotarea (not the margins)

Argument | Default | Description
--- | --- | ---
$aColor |  | Color

Description:
Specify color for the plotarea (not the margins)
See also:

- Graph::SetFrame()
- Graph::SetMarginColor()

Example:

$graph->SetColor(? wheat?);

Graph ::
SetCSIMImgAlt($aAlt)
Set the Alt text used for the IMG tag generated for CSIM

Argument | Default | Description
--- | --- | ---
$aAlt |  | Alt text

Description:
Set the ALt text used for the IMG tag generated for CSIM. Whne calling StrokeCSIM() a HTML page will be returned witha recusrive call to teh same script in an IMG tag. This method allows you to specify the Alt text to be used in the returned HTML page.
See also:

- Graph::StrokeCSIM()

Example:

$graph->SetCSIMImgAlt('Yearly values');
$graph->StrokeCSIM();

Graph ::
SetFrame($aDrawImgFrame, $aImgFrameColor, $aImgFrameWeight)
Set a frame around the entire image

Argument | Default | Description
--- | --- | ---
$aDrawImgFrame | true | True=Draw a frame around the entire image
$aImgFrameColor | array(0,0,0) | Frame color
$aImgFrameWeight | 1 | Width of frame

Description:
Sets a frame (rectangle) of the chosen color around the edges of the image. Note: For implementation reasons the frame must be enabled in order to for a specified gradient background to show up.
See also:

- Graph::SetMarginColor()

Example:

$graph->SetFrame(true,'darkblue',2);

Graph ::
SetFrameBevel($aDepth, $aBorder, $aBorderColor, $aColor1, $aColor2, $aFlg)
Specify a abevel frame around the entire graph

Argument | Default | Description
--- | --- | ---
$aDepth | 3 | Depth (Height) in pixels for bevel
$aBorder | false | True=Add 1 pixel border around
$aBorderColor | 'black' | Border color
$aColor1 | 'white@0.4' | Right and bottom shadow
$aColor2 | 'darkgray@0.4' | Left and top shadow
$aFlg | true | True=Show bevel frame

Description:
Specify a a bevel frame around the entire graph. A Bevel frame will give the entire graph a "3D" uprised feel.

Example:

$graph->SetFrameBevel(2,true,'black');

Graph ::
SetGridDepth($aDepth)
Should the grid be in front or back of the plot?

Argument | Default | Description
--- | --- | ---
$aDepth |  | Grid depth

Description:
Specify if the grid in the plot should be drawn under or on top of the actual plots.

Valid values for grid depth are

- DEPTH_BACK, Under plots
- DEPTH_FRONT, On top of plots

The default is to draw the grid lines under the plots.

Example:

$graph->SetGridDepth(DEPTH_FRONT);

Graph ::
SetIconDepth($aDepth)
Determine if Icons should be under or over the plot

Argument | Default | Description
--- | --- | ---
$aDepth |  | Depth of icons (see description)

Description:
Determine if Icons should be under or over the plot. The argument is one of

- DEPTH_BACK
- DEPTH_FRONT

By default the icons are drawn under the plots

Example:

// Put the icons in front of the plot
$graph->SetIconDepth(DEPTH_FRONT);

Graph ::
SetImgFormat($aFormat, $aQuality)
Set Image format and optional quality

Argument | Default | Description
--- | --- | ---
$aFormat |  | Format (see description)
$aQuality | 75 | Quality parameter for JPEG

Description:
Specify what image format the generated image should use. By default the library will try to create PNG images and if the PNG libraries are not available then it will try to use foirst JPEG and finally GIF encoding.

The image format is specified as a string that can be one of

- "PNG", Looseless format with good quality/compression ratio for line graphs
- "JPEG", JPEG format
- "GIF", GIF Format

The PNG format gives in general best compression for ordinary data plots and is also a looseless format.

If the graph has complicated background images or 100s of colors then there is a good chance that JPEG will give better compression on the expense of image quality.

The quality parameter is a value between (0,100) inclusively. = gives best compression but worst quality and 100 give the best quality. Suitable ranges is 60-90.

Example:

// Set JPEG format with 60% quality
$graph->SetImgFormat('jpeg',60);

Graph ::
SetMargin($lm, $rm, $tm, $bm)
Specify side margins for graph

Argument | Default | Description
--- | --- | ---
$lm |  | Left margin (in pixels)
$rm |  | Right margin (in pixels)
$tm |  | Top margin (in pixels)
$bm |  | Bottom margin (in pixels)

Description:
Specify the margin around the actual plot area. This is actually just a shortcut for the Image::SetMargin()

Note: If you want to set the margin for a 90 degrees rotated graph please consider using Graph::Set90AndMargin() instead since this will automatically adjust for the rotated image and the swapped meaning of width and height.

See also:

- Image::SetMargin()

Example:

$graph->SetMargin(40,20,60,20);

Graph ::
SetMarginColor($aColor)
Specify color for the margins (all areas outside the plotarea)

Argument | Default | Description
--- | --- | ---
$aColor |  | Color

Description:
Specifies the color of the area between the plot area and the edge of the image.
See also:

- Graph::SetColor()
- Graph::SetFrame()

Example:

$graph->SetMarginColor('silver');

Graph ::
SetScale($aAxisType, $aYMin, $aYMax, $aXMin, $aXMax)
Specify scale to use for X and Y axis

Argument | Default | Description
--- | --- | ---
$aAxisType |  | Type of axis
$aYMin | 1 | Y-min
$aYMax | 1 | Y-max
$aXMin | 1 | X-min
$aXMax | 1 | X-max

Description:
Specifies what kind of scales should be used in the graph. The following combinations are allowed

- Linear scale. Both X and Y axis
- Logarithmic scale. Both X and Y axis
- Text scale. Only on X axis
- Integer scale. X and Y axis

Any combination of these may be used. Linear and logarithmic scales are pretty straightforward. The text scale might deserve some explanation. The easiest way to think of the text scale is as a linear scale consisting of only natural numbers, i.e. 0,1,2,3,4,? . This scale is used when you just have a number of Y-values you want to plot in a consecutive order and don?t care about the X-values. It is also used when you need to have text labesl you specify (via $graph->xaxis->SetTickLabels($labels) ).

To specify which combination of X and Y scales you want to use the $axtype parameter is specified. In this parameter you specify, by a text string, the type of scale you want to use for both X and Y scale.

Possible values for each axis are:
X: 'lin', 'text', 'log', 'int'
Y: 'lin', 'log', 'int'

Example of possible combination:

- SetScale('textint');
- SetScale('loglog');
- SetScale('linlog');

It is normally recommended to use the auto-scaling feature since for most practical purposes it is good enough. However on rare occasions you might want to specify the limits yourself. This is then done by the rest of the parameters to the method.

Note: If you want to use a logarithmic scale you must make sure that the ?jpgraph_log.php? is included.

Note1: Note that if you manually specify the scale you can also specify the tick distance with a call to Ticks::Set(). For example $graph->yaxis->scale->ticks->Set(10,5) If yiou don't ste it manually a suitable tick distance will be automatically choosen. Note2: If you want to keep the autoscaling for Y-axis but specify the X-axis then just call the method with both min and max set to 0 (e.g. SetScale('linlin',0,0,0,50); )

Example:

//----------------------
// EXAMPLE1: Using autoscaling
$graph->SetScale('textlin');
//----------------------
// EXAMPLE2: Using manual scale for Y-scale and only major ticks
$graph->SetScale('linlin',5,75);
$graph->yaxis->scale->ticks->Set(10); // Set major and minor tick to 10
//----------------------
// EXAMPLE3: Using manual scale for Y-scale
$graph->SetScale('linlin',5,200);
// Set major tick dist to 40 and minor to 20
$graph->yaxis->scale->ticks->Set(40,20);
//----------------------
// EXAMPLE4: Using manual scale for both X and Y-scale
$graph->SetScale('linlin',5,200,0,100);
// Set major tick dist to 40 and minor to 20
$graph->yaxis->scale->ticks->Set(40,20);
// Set major and minor tick dist to 20
$graph->xaxis->scale->ticks->Set(20);
// Keeping the Autoscaling for Y-axis but fixing the X
// scale to an integer scale between [0,50]
$graph->SetScale('intlin',0,0,0,50);

Graph ::
SetShadow($aShowShadow, $aShadowWidth, $aShadowColor)
Add a drop shadow to the image

Argument | Default | Description
--- | --- | ---
$aShowShadow | true | True=add a drop shadow
$aShadowWidth | 5 | Width (in pixels of shadow)
$aShadowColor | array(102,102,102) | Shadow color

Description:
Sets a frame with a drop down shadow around the entire image
See also:

- Graph::SetFrame()

Example:

$graph->SetShadow();

Graph ::
SetTextScaleAbsCenterOff($aOff)
// Text width of bar to be centered in absolute pixels

Argument | Default | Description
--- | --- | ---
$aOff |  | No description available

Description:
No description available.

Graph ::
SetTickDensity($aYDensity, $aXDensity)
Specify how dense the ticks should be drawn

Argument | Default | Description
--- | --- | ---
$aYDensity | TICKD_NORMAL | Y-density
$aXDensity | TICKD_NORMAL | X-density

Description:
This method is used to hint how many ticks the auto-scaling should try to fit on each of the axis.

The following DEFINES may be used to hint to the auto-scaling how many ticks should be allocated

- TICKD_DENSE, Small distance between ticks
- TICKD_NORMAL, Default value
- TICKD_SPARSE, Longer distance between ticks
- TICKD_VERYSPARSE, Very few ticks

Example:

$graph->SetTickDensity(TICKD_DENSE); // Many Y-ticks

Graph ::
SetTitleBackground($aBackColor, $aStyle, $aFrameStyle, $aFrameColor, $aFrameWeight, $aBevelHeight, $aEnable)
Specify background style for graph titles

Argument | Default | Description
--- | --- | ---
$aBackColor | 'gray' | Background color
$aStyle | TITLEBKG_STYLE1 | Background size style, see description
$aFrameStyle | TITLEBKG_FRAME_NONE | Frame style, see description
$aFrameColor | 'black' | Frame color
$aFrameWeight | 1 | Frame thickness (weight)
$aBevelHeight | 3 | Bevel height used for frame style bevel
$aEnable | true | Enable/disable background

Description:
Specify background style for graph titles, i.e. the background style for Graph::title, Graph::subtitle, Graph::subsubtitle. The actual background style is specified with the two arguments $aStyle and $aFrameStyle.

The first argument $aStyle determines the size the background should cover. The two possibilities are

- TITLEBKG_STYLE1, FIll the background inside the graph frame
- TITLEBKG_STYLE2, Also covers the graph frame
- TITLEBKG_STYLE3, Used together with the Bevel frame. WIll put the title beackground under the graph bevel.

The second style parameter specifies what type of frame should be drawn. The weight of the frame is adjustable by specifying the $aFrameweight argument. The possible options for frame styles are:

- TITLEBKG_FRAME_NONE, No frame
- TITLEBKG_FRAME_FULL, Full frame around the background
- TITLEBKG_FRAME_BOTTOM, Just a line at the bottom
- TITLEBKG_FRAME_BEVEL, Draw a Bevel 3D effect (looks like a raised square button). The height of the bevel can be adjusted with the $aBevelHeight argument.

You can further adjust the style of the background fill by the SetTitleBackgroundFillStyle() method.
See also:

- Image::Bevel()
- Graph::SetTitleBackgroundFillStyle()

Example:

$graph->SetTitleBackground('wheat2',TITLEBKG_STYLE1,TITLEBKG_FRAME_BOTTOM);

Graph ::
SetTitleBackgroundFillStyle($aStyle, $aColor1, $aColor2)
Adjust the title background fill style

Argument | Default | Description
--- | --- | ---
$aStyle |  | Fill style (see description)
$aColor1 | 'black' | Color 1
$aColor2 | 'white' | Color 2

Description:
The background for the graph titles as set by SetTitleBackground() can be further adjusted with this method. The style can be sepcified as one of

- TITLEBKG_FILLSTYLE_HSTRIPED, Alternating horizontal lines of color 1 and color 2
- TITLEBKG_FILLSTYLE_VSTRIPED, Alternating vertical lines of color 1 and color 2
- TITLEBKG_FILLSTYLE_SOLID, A solid fill color (default)

Example:

$graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED,'darkgreen','black');

Graph ::
SetUserFont($aNormal, $aBold, $aItalic, $aBoldIt)

Argument | Default | Description
--- | --- | ---
$aNormal |  | No description available
$aBold | '' | No description available
$aItalic | '' | No description available
$aBoldIt | '' | No description available

Description:
No description available.

Graph ::
SetUserFont1($aNormal, $aBold, $aItalic, $aBoldIt)

Argument | Default | Description
--- | --- | ---
$aNormal |  | No description available
$aBold | '' | No description available
$aItalic | '' | No description available
$aBoldIt | '' | No description available

Description:
No description available.

Graph ::
SetUserFont2($aNormal, $aBold, $aItalic, $aBoldIt)

Argument | Default | Description
--- | --- | ---
$aNormal |  | No description available
$aBold | '' | No description available
$aItalic | '' | No description available
$aBoldIt | '' | No description available

Description:
No description available.

Graph ::
SetUserFont3($aNormal, $aBold, $aItalic, $aBoldIt)

Argument | Default | Description
--- | --- | ---
$aNormal |  | No description available
$aBold | '' | No description available
$aItalic | '' | No description available
$aBoldIt | '' | No description available

Description:
No description available.

Graph ::
SetY2OrderBack($aBack)
Specify that plots on the Y2 axis should be under Y axis plots

Argument | Default | Description
--- | --- | ---
$aBack | true | TRUE=under Y axis, FALSE=above

Description:
Set the depth for Y2 plots as compare to plots added to the Y axis

Example:

$graph->SetY2OrderBack();

Graph ::
SetY2Scale($aAxisType, $aY2Min, $aY2Max)
Specify secondary Y scale

Argument | Default | Description
--- | --- | ---
$aAxisType | 'lin' | Type of scale
$aY2Min | 1 | Y2Min value
$aY2Max | 1 | Y2Max value

Description:
The graph allows two different Y-scales to be used and you can choose which one you want to use for a specific plot by the way you are adding the plot to the graph, either by Add() or by AddY2() method.

This method works in the exact same way for the Y2 axis as the SetScale() method previously described.

Allowed values for the $axtype are

- ?lin?, Linear scale
- ?log?, Logarithmic scale
- ?int?, Integer scale

Note: If you want to use a logarithmic scale you must make sure that the ?jpgraph_log.php? is included.
See also:

- Graph::SetScale()
- Graph::AddY2()

Example:

// Left Y scale linear and right Y-scale logarithmic
$graph = new Graph(300,200);
$graph->SetScale(? textlin?);
$graph->SetY2Scale(? log?);

Graph ::
SetYDeltaDist($aDist)
Set the delta position (in pixels) between the multiple Y-axis

Argument | Default | Description
--- | --- | ---
$aDist |  | Distance in pixels

Description:
Set the delta position (in pixels) between the multiple Y-axis

Graph ::
SetYScale($aN, $aAxisType, $aYMin, $aYMax)
Specify scale for additional Y-axis

Argument | Default | Description
--- | --- | ---
$aN |  | Index of axis
$aAxisType | "lin" | Scale type of axis
$aYMin | 1 | Optional min scale value
$aYMax | 1 | Optional max scale value

Description:
Specify scale for additional Y-axis

Example:

<? php
include ("../jpgraph.php");
include ("../jpgraph_line.php");
$datay = array(5,3,7,2);
$datay2 = array(88,10,55,42);
$datay3 = array(255,35,745,244);
$datay4 = array(130,97,68,119);
// Setup the graph
$graph = new Graph(600,250);
$graph->SetMargin(30,200,20,20);
$graph->SetMarginColor('white');
$graph->SetColor('lightgray');
$graph->SetScale("intlin");
$graph->SetYScale(0,"lin");
$graph->SetYScale(1,"lin");
$graph->SetYScale(2,"lin");
$p1 = new LinePlot($datay);
$p1->SetColor('blue');
$graph->Add($p1);
$p2 = new LinePlot($datay2);
$p2->SetColor('darkred');
$graph->AddY(0,$p2);
$graph->ynaxis[0]->SetColor('darkred');
$p3 = new LinePlot($datay3);
$p3->SetColor('red');
$graph->AddY(1,$p3);
$graph->ynaxis[1]->SetColor('red');
$p4 = new LinePlot($datay4);
$p4->SetColor('blue');
$graph->AddY(2,$p4);
$graph->ynaxis[2]->SetColor('blue');
// Output line
$graph->Stroke();

Graph ::
Stroke($aStrokeFileName)
Stroke graph to browser or file

Argument | Default | Description
--- | --- | ---
$aStrokeFileName | '' | File name* (or special handle, see below)

Description:
Should be the final method called in the script that generates a graph. This will generate the image and send it back to the browser.

If $aStrokeFileName != "" the image will be written to this file and NOT streamed back to the browser

If the file name is specified with the define __IMG_HANDLER (Note: Thre are 2 '_' in the beginning) then no image will be streamed to file or browser. Instead the Stroke() method will simply return the image handle used by the GD library. This can come in handy of you like to post manipulate the image or use the raw GD image in other context. Such as in creating dynamic PDF documents.

Note: If you want to use the image in a PDF file you can't take the handle directly since this is a GD handle. To use it in PDF you must first create an PDF image by calling pdf_open_memory_image() to get a proper PDF image handle. See example below.

You may also specify the file name as "auto" in which case the filename will be created from the script name but with the extension changed to reflect the choosen image format.

Example:

// Example 1 : (Normal case) Stream back to browser
$graph->Stroke();
// Example 2 : Stream to the file with absolute file path
$graph->Stroke($fileName);
// Example 3
// Get the image handle. NOTE: No image will be
// streamed to the browser in this case.
$ih = $graph->Stroke(__IMG_HANDLER);
// PDF example
//....
$im = $graph->Stroke(_IMG_HANDLER);
$pdf = pdf_new();
pdf_open_file($pdf, "");
$pimg = pdf_open_memory_image($pdf, $im);
pdf_begin_page($pdf, 595, 842);
pdf_add_outline($pdf, "Page 1");
pdf_place_image($pdf, $pimg, 0, 500, 1);
pdf_close_image($pdf, $pimg);
pdf_end_page($pdf);
pdf_close($pdf);
$buf = pdf_get_buffer($pdf);
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=jpimage.pdf");
echo $buf;
pdf_delete($pdf);

Graph ::
StrokeCSIM($aScriptName, $aCSIMName, $aBorder)
Stroke an image with a CSIM

Argument | Default | Description
--- | --- | ---
$aScriptName | 'auto' | Name of the image generating script
$aCSIMName | '' | Image map name
$aBorder | 0 | Should the image be bordered?

Description:
To generate an CSIM you must use this method at the end of your script instead of the normal Graph::Stroke() method. This method does not send back an image to the browser but rather a HTML page which contains an image map and a "recursive call" back to the image script. See the full JpGraph manual for a detailed explanation on how this works.

Please note that it is abolutely imperative that you specify the image generating scripts name as the first argument.

Why that? Because it is impossible for JpGraph to find out the name of the script it is executed from in the case where it is included as oart of a "standard" HTML/PHP page. Using the PHP_SELF will only return the master document and not the actual script name.

If you use several image map images on the same HTML page you must also specify unique names of each of the image maps as the second argument for this function.

To specify targets for the image maps you must call the individual plots Pot::SetCSIMTargets()

Tip: You can easily specify the script name by using the construction basename(__FILE__) as the first argument

See also:

- Plot::SetCSIMTargets()

Example:

...
$graph->StrokeCSIM(basename(__FILE__));

Graph ::
StrokeCSIMImage()
// Construct wrapper HTML and write to file and send it back to browser// In the src URL we must replace the '?' with its encoding to prevent the arguments// to be converted to real arguments.

Description:
No description available.

Graph ::
StrokeFrameBackground()
Stroke the frames background and border

Description:
Semi Internal routine. Exclusively used together with canvas graphs where object are added directly to the canvas and we therefore must make sure that the background is stroked first.

Example:

e

Graph ::
StrokeStore($aStrokeFileName)
// DO Nothing. It gets too messy to do this properly for 90 deg...

Argument | Default | Description
--- | --- | ---
$aStrokeFileName |  | No description available

Description:
No description available.

Graph ::
__construct($aWidth, $aHeight, $aCachedName, $aTimeOut, $aInline)
Creates a new graph.

Argument | Default | Description
--- | --- | ---
$aWidth | 300 | Width
$aHeight | 200 | Height
$aCachedName | '' | Cache file name
$aTimeOut | 0 | Timeout value for cache
$aInline | true | True=Stream the image back to the browser

Description:
Creates a new graph. This is often the first call made to set-up a new graph.
If the cache name is specified (via the $aCachedname) argument then this method will first try to locate the named file in the cache directory (as specified by the DEFINE in jpgraph.php) rather then generating the graph on the fly. If the file is not there or if it is older then the specified timeout value ($aTimeOut) the graph will be generated and saved as the specified file.

If the cache name is specifed as 'auto' then the cache name will be based on the basename of the script with an extension indicating the image format used, i.e. JPG, GIF or PNG.

If the specified file is found in the cache directory then it will be streamed back to the browser directly.

If no cache name is specified then the graph will always be generated and the cache bypassed. The same is true if the DEFINE 'USE_CACHE' or 'READ_CACHE' is set to false.

Before any other operation is performed on the graph a call to SetScale() should be made to finish the initialisation of the graph.

See also:

- Graph::Stroke()

Example:

// Example 1. use cache and automtic create the cache name
$graph = new Graph(400,200,"auto");
$graph->img->SetMargin(60,20,30,50);
$graph->SetScale("textlin");
$graph->SetMarginColor("silver");
$graph->SetShadow();
// Example 2 . Don't use the cache
$graph = new Graph(400,200);
$graph->SetScale("textint");