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.

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.

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);

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

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.

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.

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.

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.

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.

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.

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); )

//----------------------
// 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);

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.

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.

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.

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

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.