You are on page 1of 108

Documentation

This documentation has been last updated on 06/18/2008.

pChart - a chart drawing library

Thank you for using pChart, we hope that you'll find the answer to your questions in this
documentation. If not, feel free to use the dedicated sourceforge forum and tracker.

Drawing a chart can be cut in 3 parts : First, get access to the data and prepare it to be graphed ( you
can use the pData class to help ). Second, prepare the graph design : rounded corners, freaky
background, drawing area and then draw the chart! Last step, put some labels, title and legends.
Your chart can now be saved in a web server folder or sent directly to the client browser.

Using the library

This class can be invoked for realtime picture drawing or cron/scheduled tasks. Rendering a graph
is CPU consuming, we recomment that all static graphs ( or with a renewal interval of more than 10
minutes ) should be computed from a cron job, this also apply to web sites serving a lot of page
views.
pChart is using the GD library to create pictures. You must compile the GD library with the
freetype extension when installing PHP on a linux server. On windows operating system you
must add the GD extension in your php.ini file. GD support is a mandatory prerequisite and
cannot be overriden. You can use the following tutorial if you don't know how to install it on
a linux server.

If you plan to use pChart on a production web service, keep an eye on project updates &
progress list. We'll try to focus on increasing the graphical render speed.

A section of this documentation is dedicated on how to use pChart to render scheduled


jobs ( windows & linux )

This graph is a simple -naked- rendering using the pChart library:


1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7));
9. $DataSet->AddSerie();
10.$DataSet->SetSerieName("Sample data","Serie1");
11.
12.// Initialise the graph
13.$Test = new pChart(700,230);
14.$Test->setFontProperties("Fonts/tahoma.ttf",10);
15.$Test->setGraphArea(40,30,680,200);
16.$Test->drawGraphArea(252,252,252);
17.$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
18.$Test->drawGrid(4,TRUE,230,230,230,255);
19.
20.// Draw the line graph
21.$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
22.$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
23.
24.// Finish the graph
25.$Test->setFontProperties("Fonts/tahoma.ttf",8);
26.$Test->drawLegend(45,35,$DataSet->GetDataDescription(),255,255,255);
27.$Test->setFontProperties("Fonts/tahoma.ttf",10);
28.$Test->drawTitle(60,22,"My pretty graph",50,50,50,585);
29.$Test->Render("Naked.png");
30.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7));
$DataSet->AddSerie();
$DataSet->SetSerieName("Sample data","Serie1");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->setGraphArea(40,30,680,200);
$Test->drawGraphArea(252,252,252);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,255);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(45,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"My pretty graph",50,50,50,585);
$Test->Render("Naked.png");
?>

pChart.class - Drawing library

This class contains all the graphical stuff. You'll find bellow a short summary of all the embeded
function and their related parameters. This documentation has last been updated to match release
1.27 changes.

Class initialisation
pChart($XSize,$YSize)
Draw methods
drawBackground($R,$G,$B)
drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B)
drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100)
drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)
drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)
drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)
drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE)
drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B)
drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)
drawFromPNG($FileName,$X,$Y,$Alpha=100)
drawFromGIF($FileName,$X,$Y,$Alpha=100)
drawFromJPG($FileName,$X,$Y,$Alpha=100)
Graph setup methods
addBorder($Width=3,$R=0,$G=0,$B=0)
clearScale()
clearShadow()
createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades)
drawGraphArea($R,$G,$B,$Stripe=FALSE)
drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,
$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)
drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,
$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1)
drawXYScale(&$Data,&$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,
$Angle=0,$Decimals=1)
drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=255)
drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-
1,$Rt=0,$Gt=0,$Bt=0,$Border=FALSE)
drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B)
drawTextBox($X1,$Y1,$X2,$Y2,$Text,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$BgR=-
1,$BgG=-1,$BgB=-1,$Alpha=100)
drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)
drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,
$TickWidth=4,$FreeText=NULL)
drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50)
drawRadarAxis($Data,$DataDescription,$Mosaic=TRUE,
$BorderOffset=10,$A_R=60,$A_G=60,$A_B=60,$S_R=200,$S_G=200,$S_B=200,$MaxValue=-
1)
drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA)
getLegendBox($DataDescription)
loadColorPalette($FileName,$Delimiter=",")
reportWarnings($Interface="CLI")
setGraphArea($X1,$Y1,$X2,$Y2)
setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,$R=210,$G=210,$B=210)
setColorPalette($ID,$R,$G,$B)
setCurrency($Currency)
setDateFormat($Format)
setFontProperties($FontName,$FontSize)
setLineStyle($Width=1,$DotSize=0)
setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMin=0,$XDivisions=5)
setShadowProperties($ShadowXDistance=4,$ShadowYDistance=4,$ShadowRColor=60,$Shadow
GColor=60,$ShadowBColor=60)
writeValues($Data,$DataDescription,$Series)
Graphs methods
drawPlotGraph(&$Data,&$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-
1,$B2=-1,$Shadow=FALSE)
drawXYPlotGraph(&$Data,&$DataDescription,$YSerieName,$XSerieName,
$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1)
drawLineGraph($Data,$DataDescription)
drawXYGraph(&$Data,&$DataDescription,$YSerieName,$XSerieName,$PaletteID=0)
drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE)
drawCubicCurve($Data,$DataDescription,$Accuracy)
drawFilledCubicCurve($Data,$DataDescription,$Accuracy,$Alpha=100,$AroundZero=FALSE)
drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)
drawBarGraph($Data,$DataDescription,$Shadow=FALSE)
drawOverlayBarGraph($Data,$DataDescription,$Alpha=50)
drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)
drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1)
drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1)
drawPieGraph($Data,$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,
$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0)
drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0)
drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals=0)
drawFlatPieGraphWithShadow(&$Data,&$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0)
Rendering methods :
setImageMap($Mode=TRUE,$GraphID="MyGraph")
getImageMap($MapName,$Flush=TRUE)
Render($FileName)
Stroke()

pChart

void pChart($XSize,$YSize)

This function create a new chart object. This object will be used during all the steps of the graph
creation. This object will embed all the pChart functions.

1. // This will create a 700x230 picture


2. $MyPicture = new pChart(700,230);
// This will create a 700x230 picture
$MyPicture = new pChart(700,230);

drawBackground
void drawBackground($R,$G,$B)

This function can be used to set the graph background color. In many cases this isn't needed. The
default graph background color is set to white (255,255,255).
1. // This will draw a red background
2. $MyPicture->drawBackground(255,0,0);
// This will draw a red background
$MyPicture->drawBackground(255,0,0);

drawRectangle
void drawRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B)

This function draw an aliased rectangle. The upper left and bottom right border positions are used
as first 4 arguments. The last 3 parameters are used to set the border color.
1. // This will draw a red square at (10,10)-(100,100)
2. $MyPicture->drawRectangle(10,10,100,100,255,0,0);
// This will draw a red square at (10,10)-(100,100)
$MyPicture->drawRectangle(10,10,100,100,255,0,0);
drawFilledRectangle
void drawFilledRectangle($X1,$Y1,$X2,$Y2,$R,$G,$B,$DrawBorder=TRUE,$Alpha=100)

The syntax of this function is the same as the drawRectangle function. This function draw an
aliased filled rectangle. The upper left and bottom right border positions are used as first 4
arguments. The last R,G,B parameters are used to set the border color. You can specify if the aliased
border will be drawn and the transparency.
1. // This will draw a filled red square at (10,10)-(100,100)
2. $MyPicture->drawRectangle(10,10,100,100,255,0,0);
3.
4. // This will draw a semi-transparent filled red square at (10,10)-(100,100)
5. $MyPicture->drawRectangle(10,10,100,100,255,0,0,FALSE,50);
// This will draw a filled red square at (10,10)-(100,100)
$MyPicture->drawRectangle(10,10,100,100,255,0,0);

// This will draw a semi-transparent filled red square at (10,10)-(100,100)


$MyPicture->drawRectangle(10,10,100,100,255,0,0,FALSE,50);

drawRoundedRectangle
void drawRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)

This function draw an aliased rectangle with rounded corners. The upper left and bottom right
border positions are used as first 4 arguments. Argument #5 represents the radius of the rounded
corner. The last 3 parameters are used to set the border color.
1. // This will draw a red square with rounded corner at (10,10)-(100,100)
2. $MyPicture->drawRoundedRectangle(10,10,100,100,10,255,0,0);
// This will draw a red square with rounded corner at (10,10)-(100,100)
$MyPicture->drawRoundedRectangle(10,10,100,100,10,255,0,0);

drawFilledRoundedRectangle
void drawFilledRoundedRectangle($X1,$Y1,$X2,$Y2,$Radius,$R,$G,$B)

The syntax of this function is the same as the drawRoundedRectangle function. This function
draw an aliased filled rectangle with rounded corners. The upper left and bottom right border
positions are used as first 4 arguments. Argument #5 represents the radius of the rounded corner.
The last 3 parameters are used to set the border color.
1. // This will draw a red filled square with rounded corner at (10,10)-(100,100)
2. $MyPicture->drawFilledRoundedRectangle(10,10,100,100,10,255,0,0);
// This will draw a red filled square with rounded corner at (10,10)-(100,100)
$MyPicture->drawFilledRoundedRectangle(10,10,100,100,10,255,0,0);

drawCircle
void drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)

This function draw an aliased circle at position ($Xc,$Yc) with the specified radius. The last 3
parameters are used to set the border color. Width is used to draw ellipses.
1. // This will draw a red circle at (100,100) with a radius of 50 pixel
2. $MyPicture->drawCircle(100,100,50,255,0,0);
// This will draw a red circle at (100,100) with a radius of 50 pixel
$MyPicture->drawCircle(100,100,50,255,0,0);

drawFilledCircle
void drawFilledCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)

The syntax of this function is the same as the drawCircle function. This function draw a filled
aliased circle at position ($Xc,$Yc) with the specified radius. The last 3 parameters are used to set
the border and filling color. Width is used to draw ellipses.
1. // This will draw a red filled circle at (100,100) with a radius of 50 pixel
2. $MyPicture->drawFilledCircle(100,100,50,255,0,0);
// This will draw a red filled circle at (100,100) with a radius of 50 pixel
$MyPicture->drawFilledCircle(100,100,50,255,0,0);

drawEllipse
void drawEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)

This function draw an aliased ellipse at position ($Xc,$Yc) with the specified height and width. The
last 3 parameters are used to set the border color.
1. // This will draw a red ellipse at (100,100) with a width of 50 pixel and height of 25 pixel
2. $MyPicture->drawEllipse(100,100,50,25,255,0,0);
// This will draw a red ellipse at (100,100) with a width of 50 pixel and
height of 25 pixel
$MyPicture->drawEllipse(100,100,50,25,255,0,0);

drawFilledEllipse
void drawFilledEllipse($Xc,$Yc,$Height,$Width,$R,$G,$B)

The syntax of this function is the same as the drawEllipse function. This function draw a filled
aliased ellipse at position ($Xc,$Yc) with the specified height and width. The last 3 parameters are
used to set the border and filling color.
1. // This will draw a red filled ellipse at (100,100) with a width of 50 pixel
2. // and height of 25 pixel
3. $MyPicture->drawFilledEllipse(100,100,50,25,255,0,0);
// This will draw a red filled ellipse at (100,100) with a width of 50 pixel
// and height of 25 pixel
$MyPicture->drawFilledEllipse(100,100,50,25,255,0,0);

drawLine
void drawLine($X1,$Y1,$X2,$Y2,$R,$G,$B,$GraphFunction=FALSE)

This function will draw an aliased line between points (X1,Y1) and (X2,Y2). The last 3 parameters
are used to set the line color. The last optional parameter is used for internal calls made by graphing
function. If set to TRUE, only portions of line inside the graph area will be drawn.
1. // This will draw a red line between point (0,0) and (100,100)
2. $MyPicture->drawLine(0,0,100,100,255,0,0);
// This will draw a red line between point (0,0) and (100,100)
$MyPicture->drawLine(0,0,100,100,255,0,0);

drawDottedLine
void drawDottedLine($X1,$Y1,$X2,$Y2,$DotSize,$R,$G,$B)

This function will draw an aliased dotted line between points (X1,Y1) and (X2,Y2). The last 3
parameters are used to set the line color. Parameter #5 is used to specify the dot size ( 2 will draw 1
point every 2 points )
1. // This will draw a red dotted line between point (0,0) and (100,100)
2. // Dots will consist of 5 solid points followed by a hole of 5 points
3. $MyPicture->drawDottedLine(0,0,100,100,10,255,0,0);
// This will draw a red dotted line between point (0,0) and (100,100)
// Dots will consist of 5 solid points followed by a hole of 5 points
$MyPicture->drawDottedLine(0,0,100,100,10,255,0,0);

drawAlphaPixel
void drawAlphaPixel($X,$Y,$Alpha,$R,$G,$B)

This function will draw an alpha pixel at position (X,Y). $Alpha is used to specify the transparency
factor ( between 0 and 100 ) The last 3 parameters are used to set the pixel color.
1. // This will draw a red pixel at position (100,100) and a transparency factor of 50%
2. $MyPicture->drawAlphaPixel(100,100,50,255,0,0);
// This will draw a red pixel at position (100,100) and a transparency factor
of 50%
$MyPicture->drawAlphaPixel(100,100,50,255,0,0);

drawFromPNG
void drawFromPNG($FileName,$X,$Y,$Alpha=100)

This function allows you to merge an external PNG picture with your graph specifying the position
and the transparency.
1. // This will put the picture "test.png" in the top left corner
2. $MyPicture->drawFromPNG("test.png",0,0);
3.
4. // This will put the picture "test.png" at (20-20) with 50% transparency
5. $MyPicture->drawFromPNG("test.png",20,20,50);
// This will put the picture "test.png" in the top left corner
$MyPicture->drawFromPNG("test.png",0,0);

// This will put the picture "test.png" at (20-20) with 50% transparency
$MyPicture->drawFromPNG("test.png",20,20,50);

drawFromGIF
void drawFromGIF($FileName,$X,$Y,$Alpha=100)

This function allows you to merge an external GIF picture with your graph specifying the position
and the transparency.
1. // This will put the picture "test.gif" in the top left corner
2. $MyPicture->drawFromGIF("test.gif",0,0);
3.
4. // This will put the picture "test.gif" at (20-20) with 50% transparency
5. $MyPicture->drawFromGIF("test.gif",20,20,50);
// This will put the picture "test.gif" in the top left corner
$MyPicture->drawFromGIF("test.gif",0,0);

// This will put the picture "test.gif" at (20-20) with 50% transparency
$MyPicture->drawFromGIF("test.gif",20,20,50);

drawFromJPG
void drawFromJPG($FileName,$X,$Y,$Alpha=100)

This function allows you to merge an external JPG picture with your graph specifying the position
and the transparency.
1. // This will put the picture "test.jpg" in the top left corner
2. $MyPicture->drawFromGIF("test.jpg",0,0);
3.
4. // This will put the picture "test.jpg" at (20-20) with 50% transparency
5. $MyPicture->drawFromGIF("test.jpg",20,20,50);
// This will put the picture "test.jpg" in the top left corner
$MyPicture->drawFromGIF("test.jpg",0,0);

// This will put the picture "test.jpg" at (20-20) with 50% transparency
$MyPicture->drawFromGIF("test.jpg",20,20,50);

setCurrency
void setCurrency($Currency)

Use this function to set the currency symbol.


1. // This will set the $ symbol
2. $MyPicture->setDateFormat(""$");
// This will set the $ symbol
$MyPicture->setDateFormat(""$");

setDateFormat
void setDateFormat($Format)

Use this function to set date format in the PHP notation. (see the PHP documentation ). The default
format that will be used is d/m/Y suitable for dates.
1. // This will set the date format to be hours:minutes:seconds
2. $MyPicture->setDateFormat("H:i:s");
// This will set the date format to be hours:minutes:seconds
$MyPicture->setDateFormat("H:i:s");

setFontProperties
void setFontProperties($FontName,$FontSize)

This function is used to set the font properties that will be used by all function drawing text on the
graph. Please note that the fontname must be in the current path! ( Windows & *ux version of PHP
are not handling fonts exactly the same way ).
1. // This will set the font to verdana 10 pixel height
2. $MyPicture->setFontProperties("verdana.ttf",10);
// This will set the font to verdana 10 pixel height
$MyPicture->setFontProperties("verdana.ttf",10);

setGraphArea
void setGraphArea($X1,$Y1,$X2,$Y2)

A call to this function is mandatory when creating a graph. The upper left and bottom right border
positions are used as arguments. This area will be used to draw graphs, grid, axis & more. Calling
this function will not draw anything this will only set the graph area boundaries.
1. // This will set the graph area to (30,20)-(100,80)
2. $MyPicture->setGraphArea(30,20,100,80);
// This will set the graph area to (30,20)-(100,80)
$MyPicture->setGraphArea(30,20,100,80);

setFixedScale
void setFixedScale($VMin,$VMax,$Divisions=5,$VXMin=0,$VXMin=0,$XDivisions=5)

You can use this function to skip the automatic scaling. VMin and VMax will be used to render the
graph.
1. // This will set the graph scale to 0 - 100
2. $MyPicture->setFixedScale(0,100);
3.
4. // For a scatter chart with 5 hor/ver divisions
5. $MyPicture->setFixedScale(0,100,5,0,100,5);
// This will set the graph scale to 0 - 100
$MyPicture->setFixedScale(0,100);

// For a scatter chart with 5 hor/ver divisions


$MyPicture->setFixedScale(0,100,5,0,100,5);

setShadowProperties
void
setShadowProperties($ShadowXDistance=4,$ShadowYDistance=4,$ShadowRColor=60,$Shadow
GColor=60,$ShadowBColor=60)
Use this function to set shadow properties. Can only be used with the exploded pie chart today.
1. // Activate the shadow with default settings
2. $MyPicture->setShadowProperties();
// Activate the shadow with default settings
$MyPicture->setShadowProperties();

setLineStyle
void setLineStyle($Width=1,$DotSize=0)

This function allow you to customise the way lines are drawn in charts. This function only applies
during chart drawing calls ( line charts,.. ). You can specify the width of the lines & if they are
dotted.
1. // This will set line width to 2px
2. setLineStyle(2);
3.
4. // This will set line width to 1px dotted ( 4 drawn, 4 empty..)
5. setLineStyle(1,4);
// This will set line width to 2px
setLineStyle(2);

// This will set line width to 1px dotted ( 4 drawn, 4 empty..)


setLineStyle(1,4);

addBorder
void addBorder($Width=3,$R=0,$G=0,$B=0)

Use this function to add a border to your picture. Be carefull, drawing a border will change all the
chart components positions, thus this call must be the last one before one of the rendering
methods!!! You can specify the Width of the border and its color. The width and height of the
picture will be modified by 2x the Width value.
1. // This will add a two pixel size border to the picture.
2. $MyPicture->addBorder($Width=2);
// This will add a two pixel size border to the picture.
$MyPicture->addBorder($Width=2);

clearScale
void clearScale()

You'll need to call this function only if you're planning to draw a second chart in the rendered
picture. Calling this function will clear the current scaling parameters thus you'll need to call again
the drawScale function before drawing any new chart.
1. // Reset the scaling to prepare a new chart
2. $MyPicture->clearScale();
// Reset the scaling to prepare a new chart
$MyPicture->clearScale();
clearShadow
void clearShadow()

Use this function to deactivate the shadow options. Drawing shadows is time and CPU intensive.
Shadows are today accurate for line & curve charts.
1. // Deactivate the shadow functions
2. $MyPicture->clearShadow();
// Deactivate the shadow functions
$MyPicture->clearShadow();

createColorGradientPalette
void createColorGradientPalette($R1,$G1,$B1,$R2,$G2,$B2,$Shades)

This function will fill the color palette with 10 shades between the two RGB colors 0,0,0 and
100,100,100. This will produce grey shades. (Palette ID 0-9 will be filled)
1. // Deactivate the shadow functions
2. $MyPicture->createColorGradientPalette(0,0,0,100,100,100,10);
// Deactivate the shadow functions
$MyPicture->createColorGradientPalette(0,0,0,100,100,100,10);

drawGraphArea
void drawGraphArea($R,$G,$B,$Stripe=FALSE)

This function will draw the graph area background color. The same result can be obtained using the
drawFilledRectangle function and giving coordinates manualy. The R,G,B 3 parameters are used to
set the filling color. If strip is set to TRUE, this will draw thin 45 degree strip with a color of -15.
1. // This will set the background color of the graph area to a soft grey
2. $MyPicture->drawGraphArea(250,250,250);
// This will set the background color of the graph area to a soft grey
$MyPicture->drawGraphArea(250,250,250);

drawScale
void drawScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,
$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1,$RightScale=FALSE)

This function will draw both axis and write values on it. You can disable the labelling of the axis
setting $DrawTicks to FALSE. $Angle can be used to rotate the vertical ticks labels. $Decimal
specify the number of decimal values we want to keep. Setting DrawTicks to false will not draw
vertical & horizontal ticks on the axis ( labels will also not be written ).

Today there is four way of computing scales :

- Getting Max & Min values per serie : ScaleMode = SCALE_NORMAL


- Like the previous one but setting the min value to 0 : ScaleMode = SCALE_START0
- Getting the series cumulative Max & Min values : ScaleMode = SCALE_ADDALL
- Like the previous one but setting the min value to 0 : ScaleMode = SCALE_ADDALLSTART0
This will depends on the kind of graph you are drawing, today only the stacked bar chart can use the
SCALE_ADDALL mode. Drawing graphs were you want to fix the min value to 0 you must use
the SCALE_START0 option.

You can display only one X label every Xi labels using the $SkipLabels parameter.

Keeping $WithMargin to FALSE will make the chart use all the width of the graph area. For most
graphs the rendering will be better. In some circumstances you'll have to set it to TRUE
( introducing left & right margin ) : bar charts will require it.

See the datastructure help for more informations on how to use the datasets.
1. // This will will draw both scales in black in automatic mode
2. $MyPicture->drawScale($Data,$DataDescription,SCALE_NORMAL,0,0,0);
3.
4. // This can be used for bar graphs
5. $MyPicture->drawScale($Data,
$DataDescription,SCALE_NORMAL,0,0,0,TRUE,0,0,TRUE);
6.
7. // ..same but with a min value of 0
8. $MyPicture->drawScale($Data,
$DataDescription,SCALE_START0,0,0,0,TRUE,0,0,TRUE);
9.
10.// This can be used for stacked bar graphs
11.$MyPicture->drawScale($Data,
$DataDescription,SCALE_ADDALL,0,0,0,TRUE,0,0,TRUE);
// This will will draw both scales in black in automatic mode
$MyPicture->drawScale($Data,$DataDescription,SCALE_NORMAL,0,0,0);

// This can be used for bar graphs


$MyPicture->drawScale($Data,
$DataDescription,SCALE_NORMAL,0,0,0,TRUE,0,0,TRUE);

// ..same but with a min value of 0


$MyPicture->drawScale($Data,
$DataDescription,SCALE_START0,0,0,0,TRUE,0,0,TRUE);

// This can be used for stacked bar graphs


$MyPicture->drawScale($Data,
$DataDescription,SCALE_ADDALL,0,0,0,TRUE,0,0,TRUE);

drawRightScale
void drawRightScale($Data,$DataDescription,$ScaleMode,$R,$G,$B,$DrawTicks=TRUE,
$Angle=0,$Decimals=1,$WithMargin=FALSE,$SkipLabels=1)

This function is a wrapper of the drawScale() function. It takes the same parameters of the
drawScale() function. The scale values will be written on the right side of the graph area.
1. // This will will draw both scales in black in automatic mode
2. $MyPicture->drawRightScale($Data,$DataDescription,SCALE_NORMAL,0,0,0);
3.
4. // This can be used for bar graphs
5. $MyPicture->drawRightScale($Data,
$DataDescription,SCALE_NORMAL,0,0,0,TRUE,0,0,TRUE);
6.
7. // ..same but with a min value of 0
8. $MyPicture->drawRightScale($Data,
$DataDescription,SCALE_START0,0,0,0,TRUE,0,0,TRUE);
9.
10.// This can be used for stacked bar graphs
11.$MyPicture->drawRightScale($Data,
$DataDescription,SCALE_ADDALL,0,0,0,TRUE,0,0,TRUE);
// This will will draw both scales in black in automatic mode
$MyPicture->drawRightScale($Data,$DataDescription,SCALE_NORMAL,0,0,0);

// This can be used for bar graphs


$MyPicture->drawRightScale($Data,
$DataDescription,SCALE_NORMAL,0,0,0,TRUE,0,0,TRUE);

// ..same but with a min value of 0


$MyPicture->drawRightScale($Data,
$DataDescription,SCALE_START0,0,0,0,TRUE,0,0,TRUE);

// This can be used for stacked bar graphs


$MyPicture->drawRightScale($Data,
$DataDescription,SCALE_ADDALL,0,0,0,TRUE,0,0,TRUE);

drawXYScale
void drawXYScale(&$Data,&$DataDescription,$YSerieName,$XSerieName,$R,$G,$B,
$Angle=0,$Decimals=1)

This function is used by scatter charts. It will compute everything needed to draw the associated
line and plot charts. You must specify the name of the two series that will be used as X and Y data.
By default this function will compute the min & max values of both series, anyway you can
override the automatic scaling by calling first the setFixedScale function.

See the datastructure help for more informations on how to use the datasets.
1. // This will will draw both scales in black in automatic mode
2. $MyPicture->drawXYScale($Data,$DataDescription,"Serie1","Serie2",0,0,0);
3.
4. // This can be used for bar graphs with X labels rotated
5. $MyPicture->drawXYScale($Data,$DataDescription,"Serie1","Serie2",0,0,0,45);
// This will will draw both scales in black in automatic mode
$MyPicture->drawXYScale($Data,$DataDescription,"Serie1","Serie2",0,0,0);

// This can be used for bar graphs with X labels rotated


$MyPicture->drawXYScale($Data,$DataDescription,"Serie1","Serie2",0,0,0,45);

drawGrid
void drawGrid($LineWidth,$Mosaic=TRUE,$R=220,$G=220,$B=220,$Alpha=255)

This function will draw a grid over the graph area. $LineWidth will be passed to the
drawDottedLine function. The R,G,B 3 parameters are used to set the grid color. Setting Mosaic to
true will draw grey area between two lines. You can define the transparency factor of the mosaic
area playing with the Alpha parameter.
1. // This will will draw a black grid over the graph area.
2. $MyPicture->drawGrid(4,FALSE,0,0,0);
3.
4. // This will will draw a soft grid over the graph area with greyed area.
5. $MyPicture->drawGrid(4,TRUE);
// This will will draw a black grid over the graph area.
$MyPicture->drawGrid(4,FALSE,0,0,0);

// This will will draw a soft grid over the graph area with greyed area.
$MyPicture->drawGrid(4,TRUE);

drawLegend
void drawLegend($XPos,$YPos,$DataDescription,$R,$G,$B,$Rs=-1,$Gs=-1,$Bs=-
1,$Rt=0,$Gt=0,$Bt=0,$Border=FALSE)

This function will draw the legend of the graph ( serie color & serie name ) at the specified position.
The R,G,B parameters are used to set the background color. You can optionally provide the shadow
color using the Rs,Gs,Bs parameters. You can also customize the text color using the Rt,Gt,Bt.
Setting Border to false remove the surrounding box.

See the datastructure help for more informations on how to use the datasets.
1. // This will will draw the name of the series at (30-30) in a white buble
2. $MyPicture->drawLegend(30,30,$DataDescription,255,255,255);
// This will will draw the name of the series at (30-30) in a white buble
$MyPicture->drawLegend(30,30,$DataDescription,255,255,255);

drawPieLegend
void drawPieLegend($XPos,$YPos,$Data,$DataDescription,$R,$G,$B)

This function will draw the legend of a pie graph ( serie color & value name ). Be carrefull, dataset
used for pie chart are not the same than for other line / curve / plot graphs. You can specify the
position of the legend box and the background color.

See the datastructure help for more informations on how to use the datasets.
1. // This will will draw the data values names at (10-10) with a light grey background
2. $MyPicture->drawPieLegend(10,10,$Data,$DataDescription,250,250,250);
// This will will draw the data values names at (10-10) with a light grey
background
$MyPicture->drawPieLegend(10,10,$Data,$DataDescription,250,250,250);

drawTextBox
void drawTextBox($X1,$Y1,$X2,$Y2,$Text,
$Angle=0,$R=255,$G=255,$B=255,$Align=ALIGN_LEFT,$Shadow=TRUE,$BgR=-1,$BgG=-
1,$BgB=-1,$Alpha=100)

Use this function to write text over the picture. You must specify the coordinate of the box where
the text will be written using the (X1,Y1)-(X2,Y2) parameters, the text angle and the text color with
the R,G,B parameters. You can choose how the text will be aligned with the Align parameter :

- ALIGN_TOP_LEFT Use the box top left corner.


- ALIGN_TOP_CENTER Use the box top center corner.
- ALIGN_TOP_RIGHT Use the box top right corner.
- ALIGN_LEFT Use the center left.
- ALIGN_CENTER Use the center.
- ALIGN_RIGHT Use the center right.
- ALIGN_BOTTOM_LEFT Use the box bottom left corner.
- ALIGN_BOTTOM_CENTER Use the box bottom center corner.
- ALIGN_BOTTOM_RIGHT Use the box bottom right corner.

Use the Shadow parameter to define if the text will own a shadow. Specifying the BgR,BgG,BgB
will draw fill the text area with the associated color. The Alpha parameter will be applyed to the text
box background.
1. // This will will draw a text box with a black background and a transparency of 30%
2. // the text will be written in white with a shadow
3. $MyPicture->drawTextBox(0,210,700,230,"My text goes here",0,255,255,255,ALIGN_RIG
HT,TRUE,0,0,0,30);
// This will will draw a text box with a black background and a transparency
of 30%
// the text will be written in white with a shadow
$MyPicture->drawTextBox(0,210,700,230,"My text goes
here",0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);

drawTitle
void drawTitle($XPos,$YPos,$Value,$R,$G,$B,$XPos2=-1,$YPos2=-1,$Shadow=FALSE)

This function is used to write the graph title. Used with default parameters you must specify the
bottom left position of the text. If you are specifying $X2 and $Y2 the text will be centered
horizontaly and verticaly in the box of coordinates (X1,Y1)-(X2,Y2). $Value correspond to the text
that will be written on the graph. $R, $G and $B are used to set the text color. Setting Shadow to
true will makes a shadow behind the text.
1. // This will write in black "This is the title" at coordinate (100,15)
2. $MyPicture->drawTitle(100,15,"This is the title",0,0,0);
// This will write in black "This is the title" at coordinate (100,15)
$MyPicture->drawTitle(100,15,"This is the title",0,0,0);

drawTreshold
void drawTreshold($Value,$R,$G,$B,$ShowLabel=FALSE,$ShowOnRight=FALSE,
$TickWidth=4,$FreeText=NULL)

This function will draw an horizontal treshold ( this is an easy way to draw the 0 line ). If
$ShowLabel is set to TRUE, the value of the treshold will be written over the graph. If
$ShowOnRight is set to TRUE, the value will be written on the right side of the graph. $R, $G and
$B are used to set the line and text color. Use $TickWidth to set the width of the ticks, if set to 0 this
will draw a solid line. You can optionnaly provide the caption of the treshold (by default the
treshold value is used)
1. // This will draw a red line at vertical coordinate 0 ( using the graph coordinates system )
2. $MyPicture->drawTreshold(0,255,0,0);
// This will draw a red line at vertical coordinate 0 ( using the graph
coordinates system )
$MyPicture->drawTreshold(0,255,0,0);

setLabel
void setLabel($Data,$DataDescription,$SerieName,$ValueName,$Caption,
$R=210,$G=210,$B=210)

This function will draw a label over the graph. You must specify the Data & DataDescription
structures, the serie name ( "Serie1" by default if only one ), the X position of the value in the Data
array (will be numeric starting at 0 if no AbsciseLabel are defined or the value of the selected
Abscise serie if specified), the caption that will displayed and optionally the color of the label. To
see an example click here.

See the datastructure help for more informations on how to use the datasets.
1. // This will put a label containing the text "Important point!" on the 3rd point of Serie1 (-3)
2. $DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1");
3. $MyPicture->setLabel($Data,$DataDescription,"Serie1","2","Important point!");
4.
5. // This will put a label containing the text "February record!" on the 2nd point of Serie1 (2)
6. $DataSet->AddPoint(array(1,2,0),"Serie1");
7. $DataSet->AddPoint(array("Jan","Feb","Mar"),"Serie2");
8. $DataSet->SetAbsciseLabelSerie("Serie2");
9.
10.$MyPicture->setLabel($Data,$DataDescription,"Serie1","Feb","February record!");
// This will put a label containing the text "Important point!" on the 3rd
point of Serie1 (-3)
$DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1");
$MyPicture->setLabel($Data,$DataDescription,"Serie1","2","Important point!");

// This will put a label containing the text "February record!" on the 2nd
point of Serie1 (2)
$DataSet->AddPoint(array(1,2,0),"Serie1");
$DataSet->AddPoint(array("Jan","Feb","Mar"),"Serie2");
$DataSet->SetAbsciseLabelSerie("Serie2");

$MyPicture->setLabel($Data,$DataDescription,"Serie1","Feb","February
record!");

drawArea
void drawArea($Data,$Serie1,$Serie2,$R,$G,$B,$Alpha = 50)

This function will draw an area between two data series extracting the minimum and maximum
value for each X positions. You must specify the two series name and the area color. You can
specify the transparency which is set to 50% by default. To see an example click here.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw an area between Serie1 and Serie3 with a transparency of 50%.
2. $MyPicture->drawArea($DataSet->GetData(),"Serie1","Serie3",239,238,227,50);
// This will draw an area between Serie1 and Serie3 with a transparency of
50%.
$MyPicture->drawArea($DataSet->GetData(),"Serie1","Serie3",239,238,227,50);

drawGraphAreaGradient
void drawGraphAreaGradient($R,$G,$B,$Decay,$Target=TARGET_GRAPHAREA)

You can use this function to fill the background of the picture or of the graph area with a color
gradient pattern. You must specify the starting color with its R,G,B values, the number of shades to
apply with the Decay parameter and optionnaly the target that can be :

- TARGET_GRAPHAREA The currently defined graph area


- TARGET_BACKGROUND The whole picture background
1. // This will draw a background gradient made of 50 shades of the 132,153,172 color
2. $MyPicture->drawGraphAreaGradient(132,153,172,50,TARGET_BACKGROUND);
// This will draw a background gradient made of 50 shades of the 132,153,172
color
$MyPicture->drawGraphAreaGradient(132,153,172,50,TARGET_BACKGROUND);

drawRadarAxis
void drawRadarAxis($Data,$DataDescription,$Mosaic=TRUE,
$BorderOffset=10,$A_R=60,$A_G=60,$A_B=60,$S_R=200,$S_G=200,$S_B=200,$MaxValue=-
1)

This function will draw the axis for a radar graph. You can specify the border offset that will be
apply in the drawing area, the outer & inner axis color and the maximum value. Setting Mosaic to
false will not draw greyed area between the spider webs.
1. // This will draw the radar graph axis with auto settings
2. $MyPicture->drawRadarAxis($Data,$DataDescription);
3.
4. // This will draw the radar graph axis with a border of 20px, black
5. // axis, soft grey inner axis, using 10 as max value.
6. $MyPicture->drawRadarAxis($Data,$DataDescription,TRUE,20,0,0,0,200,200,200,10);
// This will draw the radar graph axis with auto settings
$MyPicture->drawRadarAxis($Data,$DataDescription);

// This will draw the radar graph axis with a border of 20px, black
// axis, soft grey inner axis, using 10 as max value.
$MyPicture->drawRadarAxis($Data,
$DataDescription,TRUE,20,0,0,0,200,200,200,10);

setColorPalette
void setColorPalette($ID,$R,$G,$B)
This function can be used to change the color of one series. Series ID are starting at 0 for associated
data serie #1. You must provide an RGB color.
1. // This will set the color of the first serie to red
2. $MyPicture->setColorPalette(0,255,0,0);
// This will set the color of the first serie to red
$MyPicture->setColorPalette(0,255,0,0);

loadColorPalette
void loadColorPalette($FileName,$Delimiter=",")

This function will load the color scheme from a text file. This file must be formated with three
values per line ( R,G,B ). By default the delimiter is a coma but you can specify it.
1. // This will load the palette from file includes/palette.txt using semicolon as delimiter
2. $MyPicture->loadColorPalette('includes/palette.txt','|');
// This will load the palette from file includes/palette.txt using semicolon
as delimiter
$MyPicture->loadColorPalette('includes/palette.txt','|');

reportWarnings
void reportWarnings($Interface="CLI")

Use this fonction to enable error reporting during the chart rendering. By default messages are
redirected to the console while using the render command and using GD while using the stroke
command. You can force the errors to be redirected to either CLI or GD specifying it as parameter.
1. // Enable error reporting
2. $MyPicture->reportWarnings();
3.
4. // Enable error reporting and redirect to GD
5. $MyPicture->reportWarnings("GD");
// Enable error reporting
$MyPicture->reportWarnings();

// Enable error reporting and redirect to GD


$MyPicture->reportWarnings("GD");

writeValues
void writeValues($Data,$DataDescription,$Series)

You can use this function to display the values contained in the series on top of the charts. It is
possible to specify one or multiple series to display using and array.
1. // This will show the values of Serie1 on top of the charts
2. $MyPicture->writeValues($Data,$DataDescription,"Serie1");
3.
4. // This will show the values of Serie2 and Serie3 on top of the charts
5. $MyPicture->writeValues($Data,$DataDescription,array("Serie2","Serie3"));
// This will show the values of Serie1 on top of the charts
$MyPicture->writeValues($Data,$DataDescription,"Serie1");
// This will show the values of Serie2 and Serie3 on top of the charts
$MyPicture->writeValues($Data,$DataDescription,array("Serie2","Serie3"));

drawPlotGraph
void drawPlotGraph(&$Data,&$DataDescription,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-
1,$B2=-1,$Shadow=FALSE)

This function will draw a plot graph using all the registered series. Giving only the Data &
DataDescription structure will draw the basic plot graph, you can specify the radius ( external &
internal ) of the plots. You can also specify the color of the points ( will be unique in case of
multiple series ). You can see a sample here superposing a line & a plot graph. Setting Shadow to
true will draw a shadow under the plots.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a plot graph using automatic sizing and coloring
2. $MyPicture->drawPlotGraph($Data,$DataDescription);
// This will draw a plot graph using automatic sizing and coloring
$MyPicture->drawPlotGraph($Data,$DataDescription);

drawXYPlotGraph
void drawXYPlotGraph(&$Data,&$DataDescription,$YSerieName,$XSerieName,
$PaletteID=0,$BigRadius=5,$SmallRadius=2,$R2=-1,$G2=-1,$B2=-1)

This function is very similar as the drawPlotGraph function. You must specify the name of the two
series that will be used as X and Y coordinates and the color ID to use.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a plot scatter using Serie1 as Y and Serie2 as X
2. $MyPicture->drawXYPlotGraph($Data,$DataDescription,"Serie1","Serie2");
// This will draw a plot scatter using Serie1 as Y and Serie2 as X
$MyPicture->drawXYPlotGraph($Data,$DataDescription,"Serie1","Serie2");

drawLineGraph
void drawLineGraph($Data,$DataDescription)

This function will draw a line graph using all the registered series. You can see a sample here
superposing a line & a plot graph. This function does not have optional parameters this is the most
basic one :)

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a line graph
2. $MyPicture->drawLineGraph($Data,$DataDescription);
// This will draw a line graph
$MyPicture->drawLineGraph($Data,$DataDescription);
drawXYGraph
void drawXYGraph(&$Data,&$DataDescription,$YSerieName,$XSerieName,$PaletteID=0)

This function will draw a scatter line graph. You must specify the X and Y series that will be used.
You can optionnaly set the color index in the current palette.
1. // This will draw a line scatter chart using Serie1 as Y and Serie2 as X
2. $MyPicture->drawXYGraph($Data,$DataDescription,"Serie1","Serie2");
// This will draw a line scatter chart using Serie1 as Y and Serie2 as X
$MyPicture->drawXYGraph($Data,$DataDescription,"Serie1","Serie2");

drawFilledLineGraph
void drawFilledLineGraph($Data,$DataDescription,$Alpha=100,$AroundZero=FALSE)

This function will draw a filled line graph using all the registered series. You can see a sample here.
You can provide the alpha value used when merging all series layers. If $AroundZero is set to
TRUE, the area drawn will be between the 0 axis and the line graph value.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a line graph
2. $MyPicture->drawLineGraph($Data,$DataDescription);
// This will draw a line graph
$MyPicture->drawLineGraph($Data,$DataDescription);

drawCubicCurve
void drawCubicCurve($Data,$DataDescription,$Accuracy)

This function will draw a curved line graph using all the registered series. You can see a sample
here superposing a curve & a plot graph. This curve is using a cubic algorythm to process the
average values between two points. You have to specify the accuracy between two points, typicaly a
0.1 value is acceptable. the smaller the value is, the longer it will take to process the graph.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a cubic curve graph
2. $MyPicture->drawCubicCurve($Data,$DataDescription,.1);
// This will draw a cubic curve graph
$MyPicture->drawCubicCurve($Data,$DataDescription,.1);

drawFilledCubicCurve
void drawFilledCubicCurve($Data,$DataDescription,$Accuracy,
$Alpha=100,$AroundZero=FALSE)

This function will draw a filled curved line graph using all the registered series. You can see a
sample here superposing a curve & a plot graph. This curve is using a cubic algorythm to process
the average values between two points. You have to specify the accuracy between two points,
typicaly a 0.1 value is acceptable. the smaller the value is, the longer it will take to process the
graph. You can provide the alpha value used when merging all series layers. If $AroundZero is set
to TRUE, the area drawn will be between the 0 axis and the line graph value.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a filled cubic curve graph with a transparency of 50%
2. $MyPicture->drawFilledCubicCurve($Data,$DataDescription,.1,50);
// This will draw a filled cubic curve graph with a transparency of 50%
$MyPicture->drawFilledCubicCurve($Data,$DataDescription,.1,50);

drawLimitsGraph
void drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)

This function will draw the minimum & maximum values for a specific point using all the
registered series. You can see a sample here. You can optionaly specify the vertical line color.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a limit graph
2. $MyPicture->drawLimitsGraph($Data,$DataDescription);
// This will draw a limit graph
$MyPicture->drawLimitsGraph($Data,$DataDescription);

drawBarGraph
void drawBarGraph($Data,$DataDescription,$Shadow=FALSE)

This function will draw a bar graph using all the registered series. You can see a sample here. When
creating a bar graph, don't forget to set the $WithMargin parameter of the drawScale function to
TRUE. Setting $Shadow to TRUE will draw a shadow behind each series, this will also slow down
a bit the renderer engine.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a bar graph with shadows
2. $MyPicture->drawBarGraph($Data,$DataDescription,TRUE);
// This will draw a bar graph with shadows
$MyPicture->drawBarGraph($Data,$DataDescription,TRUE);

drawStackedBarGraph
void drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)

This function will draw a stacked bar graph using all the registered series. You can see a sample
here. When creating a bar graph, don't forget to set the $WithMargin parameter of the drawScale
function to TRUE. Don't forget to change the automatic scaling to SCALE_ADDALL to have an
accurate scaling mode. You can specify the transparency and if the bars must be contiguous or with
space (default)

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a stacked bar graph with a transparency of 70%
2. $MyPicture->drawStackedBarGraph($Data,$DataDescription,70);
// This will draw a stacked bar graph with a transparency of 70%
$MyPicture->drawStackedBarGraph($Data,$DataDescription,70);

drawOverlayBarGraph
void drawOverlayBarGraph($Data,$DataDescription,$Alpha=50)

This function will draw a superposed bar graph using all the registered series. You can see a sample
here. You can provide the alpha value used when merging all series layers.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a bar graph with a default alpha factor of 50
2. $MyPicture->drawOverlayBarGraph($Data,$DataDescription);
// This will draw a bar graph with a default alpha factor of 50
$MyPicture->drawOverlayBarGraph($Data,$DataDescription);

drawRadar
void drawRadar($Data,$DataDescription,$BorderOffset=10,$MaxValue=-1)

This function will draw a line radar graph using all the registered series. You can see a sample here.
You can provide a border offset and the max value ( must be the same than the one used with the
DrawRadarAxis function for consistency )

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a line radar graph
2. $MyPicture->drawRadar($Data,$DataDescription);
// This will draw a line radar graph
$MyPicture->drawRadar($Data,$DataDescription);

drawFilledRadar
void drawFilledRadar($Data,$DataDescription,$Alpha=50,$BorderOffset=10,$MaxValue=-1)

This function will draw a filled radar graph using all the registered series. You can see a sample
here. You can provide a border offset and the max value ( must be the same than the one used with
the DrawRadarAxis function for consistency ) You can also provide the layers transparency factor
which is set to 50% by default.

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a line radar graph
2. $MyPicture->drawFilledRadar($Data,$DataDescription);
// This will draw a line radar graph
$MyPicture->drawFilledRadar($Data,$DataDescription);

drawPieGraph
void drawPieGraph($Data,$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL,$EnhanceColors=TRUE,
$Skew=60,$SpliceHeight=20,$SpliceDistance=0,$Decimals=0)
This function will draw a 3D pie graph. To do so you must specify the Data & DataDescription
array. Only one serie of data is allowed for pie graph. You can associate a description of each value
in another serie by marking it using the SetAbsciseLabelSerie() function. You must specify the
center position of the chart. You can also optionally specify the radius of the pie, if the percentage
should be printed, the 3D skew factor and the height of all splices. If $EnhanceColors is set to
TRUE, pie edges will be enhanced. If SpliceDistance is greated than 0, the pie will be exploded.
You can specify the number of decimals you want to be displayed in the labels (default is 0 ).

By default no labels are written around the pie chart. You can use the following modes for the
$DrawLabels parameter:

- PIE_NOLABEL No labels displayed


- PIE_PERCENTAGE Percentages are displayed
- PIE_LABELS Series labels displayed
- PIE_PERCENTAGE_LABEL Series labels & percentage displayed

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a pie graph centered at (150-150) with a radius of 100, no labels
2. $MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);
3.
4. // This will draw a pie graph centered at (150-150) with a radius of 50 and percentages
5. $MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,50,PIE_PERCENTAGE);
6.
7. // This will draw a pie graph centered at (150-150) with a radius of 100, captions and a skew
factor of 30
8. $MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,TRUE,30);
9.
10.// This will draw a pie graph (..) exploded
11.$MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,TRUE,30,10,10);
// This will draw a pie graph centered at (150-150) with a radius of 100, no
labels
$MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);

// This will draw a pie graph centered at (150-150) with a radius of 50 and
percentages
$MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,50,PIE_PERCENTAGE);

// This will draw a pie graph centered at (150-150) with a radius of 100,
captions and a skew factor of 30
$MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,TRUE,30);

// This will draw a pie graph (..) exploded


$MyPicture->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,TRUE,30,10,10);
drawBasicPieGraph
void drawBasicPieGraph($Data,$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL,$R=255,$G=255,$B=255,$Decimals=0)

This function will draw a classical non-exploded pie chart. To do so you must specify the Data &
DataDescription array. Only one serie of data is allowed for pie graph. You can associate a
description of each value in another serie by marking it using the SetAbsciseLabelSerie() function.
You must specify the center position of the chart. You can also optionally specify the radius of the
pie and if the percentage should be printed. $R,$G,$B can be used to set the color of the line that
will surround each pie slices. You can specify the number of decimals you want to be displayed in
the labels (default is 0 )

By default no labels are written around the pie chart. You can use the following modes for the
$DrawLabels parameter:

- PIE_NOLABEL No labels displayed


- PIE_PERCENTAGE Percentages are displayed
- PIE_LABELS Series labels displayed
- PIE_PERCENTAGE_LABEL Series labels & percentage displayed

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a pie graph centered at (150-150) with a radius of 100, no labels
2. $MyPicture->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);
3.
4. // This will draw a pie graph centered at (150-150) with a radius of 50 and percentages
5. $MyPicture->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,50,PIE_PERCENTAGE);
6.
7. // This will draw a pie graph centered at (150-150) with a radius of 100, captions and black b
orders
8. $MyPicture->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,0,0,0);
// This will draw a pie graph centered at (150-150) with a radius of 100, no
labels
$MyPicture->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);

// This will draw a pie graph centered at (150-150) with a radius of 50 and
percentages
$MyPicture->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,50,PIE_PERCENTAGE);

// This will draw a pie graph centered at (150-150) with a radius of 100,
captions and black borders
$MyPicture->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,0,0,0);

drawFlatPieGraph
void drawFlatPieGraph($Data,$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL ,$SpliceDistance=0,$Decimals=0)
This function will draw a flat 2D pie graph. To do so you must specify the Data & DataDescription
array. Only one serie of data is allowed for pie graph. You can associate a description of each value
in another serie by marking it using the SetAbsciseLabelSerie() function. You must specify the
center position of the chart. You can also optionally specify the radius of the pie and if the
percentage should be printed. If SpliceDistance is greated than 0, the pie will be exploded. You can
specify the number of decimals you want to be displayed in the labels (default is 0 )

By default no labels are written around the pie chart. You can use the following modes for the
$DrawLabels parameter:

- PIE_NOLABEL No labels displayed


- PIE_PERCENTAGE Percentages are displayed
- PIE_LABELS Series labels displayed
- PIE_PERCENTAGE_LABEL Series labels & percentage displayed

See the datastructure help for more informations on how to use the datasets.
1. // This will draw a pie graph centered at (150-150) with a radius of 100, no labels
2. $MyPicture->drawFlatPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);
3.
4. // This will draw a pie graph centered at (150-150) with a radius of 50 and percentages
5. $MyPicture->drawFlatPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,50,PIE_PERCENTAGE);
6.
7. // This will draw a pie graph centered at (150-150) with a radius of 100, captions and slightl
y exploded
8. $MyPicture->drawFlatPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,4);
// This will draw a pie graph centered at (150-150) with a radius of 100, no
labels
$MyPicture->drawFlatPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);

// This will draw a pie graph centered at (150-150) with a radius of 50 and
percentages
$MyPicture->drawFlatPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,50,PIE_PERCENTAGE);

// This will draw a pie graph centered at (150-150) with a radius of 100,
captions and slightly exploded
$MyPicture->drawFlatPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150,100,PIE_PERCENTAGE,4);

drawFlatPieGraphWithShadow
void drawFlatPieGraphWithShadow(&$Data,&$DataDescription,$XPos,$YPos,
$Radius=100,$DrawLabels=PIE_NOLABEL,$SpliceDistance=0,$Decimals = 0)

This function is an alias of the drawFlatPieGraph function.


1. // This will draw a pie graph centered at (150-150) with a radius of 100, no labels
2. $MyPicture->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);
// This will draw a pie graph centered at (150-150) with a radius of 100, no
labels
$MyPicture->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,150);

getLegendBox
array getLegendBox($DataDescription)

This function evaluate the width and height of the box generated by the drawLegend. This will help
you to calculate dynamicaly the position where you want to print it (eg top-right). You must provide
the datadescription array as only parameter. This function will return and array containing in the
first row the width of the box and in the second row the height of the box.

See the datastructure help for more informations on how to use the datasets.
1. // Retrieve the width and height of the legend box
2. $BoxSize = $MyPicture->getLegendBox($DataSet->GetDataDescription());
3.
4. // Print the legend box always aligned in the top right corner with a padding of 10px
5. // assuming your pChart graph width is 600px
6. $Test->drawLegend(590-$BoxSize[0],10,$DataSet->GetDataDescription(),255,255,255);
// Retrieve the width and height of the legend box
$BoxSize = $MyPicture->getLegendBox($DataSet->GetDataDescription());

// Print the legend box always aligned in the top right corner with a padding
of 10px
// assuming your pChart graph width is 600px
$Test->drawLegend(590-$BoxSize[0],10,$DataSet-
>GetDataDescription(),255,255,255);

setImageMap
void setImageMap($Mode=TRUE,$GraphID="MyGraph")

Use this function to start the recording of the image map that will be associated to the chart. Mode
must be set to TRUE to start recording. GraphID must be an unique identifier that will be used to
retrieve the image map using Ajax techniques. The image map will be written to the disk while
calling one of the two render method.
1. // This will start the recording of the "Zob4458" image map.
2. $MyPicture->setImageMap(TRUE,"Zob4458");
// This will start the recording of the "Zob4458" image map.
$MyPicture->setImageMap(TRUE,"Zob4458");

getImageMap
getImageMap($MapName,$Flush=TRUE)

Use this function to retrieve an image map. Most of the time this function is used to answer an ajax
asynchronous request. You must specify the image map unique ID (provided while creating it with
the setImageMap function). By default image map are flushed once they are sent to the browser,
you can keep them by setting the Flush parameter to FALSE.

If the image map cannot be found a 404 header is sent to the browser.
Calling this function will stop the execution of the script.
1. // This will sent the "Zob4458" image map and destroy the temp file
2. $MyPicture->getImageMap("Zob4458");
3.
4. // This will sent the "Zob4458" image map and keepthe temp file
5. $MyPicture->getImageMap("Zob4458",FALSE);
// This will sent the "Zob4458" image map and destroy the temp file
$MyPicture->getImageMap("Zob4458");

// This will sent the "Zob4458" image map and keepthe temp file
$MyPicture->getImageMap("Zob4458",FALSE);

pData.class - Data management for the pChart library

This class is designed to help you managing the data used to create the charts. You'll find bellow a
short summary of all the embeded function and their related parameters. Functions categories :

Class initialisation
pData()
Data populating methods
ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,
$DataName=-1)
AddPoint($Value,$Serie="Serie1",$Description="")
Series manipulation methods
AddSerie($SerieName="Serie1")
AddAllSeries()
RemoveSerie($SerieName="Serie1")
SetAbsciseLabelSerie($SerieName = "Name")
SetSerieName($Name,$SerieName="Serie1")
SetXAxisName($Name="X Axis")
SetYAxisName($Name="Y Axis")
SetXAxisFormat($Format="number")
SetYAxisFormat($Format="number")
SetXAxisUnit($Unit="")
SetYAxisUnit($Unit="")
removeSerieName($SerieName)
Series manipulation methods
GetData()
GetDataDescription()

See the datastructure help for more informations on how to use the datasets. This will help
you to better understand what is the purpose of this class.

pData
void pData()

This function create a new pData object. This object will be used during all the steps of the data
population. Data will be extracted from this object using GetData() and GetDataDescription().
1. // This will create a new pData object
2. $DataSet = new pData();
// This will create a new pData object
$DataSet = new pData();

ImportFromCSV
void ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,
$DataName=-1)

This function is used to import CSV files (local or remote). Many arguments can be used. The
default column delimiter is the comma character.
1. // This will import the file http://my.domain.com/myData.csv using each column as a serie
2. $DataSet->ImportFromCSV("http://my.domain.com/myData.csv");
3.
4. // This will import the local file path/to/myData.csv using each column as a serie
5. $DataSet->ImportFromCSV("path/to/myData.csv");
6.
7. // .. setting the column separator to pipe
8. $DataSet->ImportFromCSV("path/to/myData.csv","|");
9.
10.// .. import only the data from column 1
11.$DataSet->ImportFromCSV("path/to/myData.csv","|",1);
12.
13.// .. import only the data from column 1,2 & 3
14.$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3));
15.
16.// .. the file contains an header that will be used to name the series
17.$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3),TRUE);
18.
19.// .. column 0 will be used as label for the horizontal axis
20.$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3),TRUE,0);
// This will import the file http://my.domain.com/myData.csv using each column
as a serie
$DataSet->ImportFromCSV("http://my.domain.com/myData.csv");

// This will import the local file path/to/myData.csv using each column as a
serie
$DataSet->ImportFromCSV("path/to/myData.csv");

// .. setting the column separator to pipe


$DataSet->ImportFromCSV("path/to/myData.csv","|");

// .. import only the data from column 1


$DataSet->ImportFromCSV("path/to/myData.csv","|",1);

// .. import only the data from column 1,2 & 3


$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3));

// .. the file contains an header that will be used to name the series
$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3),TRUE);

// .. column 0 will be used as label for the horizontal axis


$DataSet->ImportFromCSV("path/to/myData.csv","|",array(1,2,3),TRUE,0);
.. for example, dealing with the following file :

ID January February March

1 0 1 0.5
2 1.204119983 4 2
3 4.294091292 9 4.5

..and importing the data with the following command ( assuming separator character is a comma ):
1. $DataSet->ImportFromCSV("path/to/myData.csv",",",array(1,2,3),TRUE,0);
$DataSet->ImportFromCSV("path/to/myData.csv",",",array(1,2,3),TRUE,0);

Will populate all the Data & DataStructure fields.


AddPoint
void AddPoint($Value,$Serie="Serie1",$Description="")

This function can be used to add one or multiple points to a data serie. By default points are added
to Serie1.
1. // This will the value 25 as the last point of Serie1
2. $DataSet->AddPoint(25);
3.
4. // This will the value 2,4,9,5,1,0 as the last point of Serie1
5. $DataSet->AddPoint(array(2,4,9,5,1,0));
6.
7. // This will the value 12 as the last point of Serie2
8. $DataSet->AddPoint(12,"Serie2");
9.
10.// .. and add the desciption "March" to the Serie2
11.$DataSet->AddPoint(12,"Serie2","March");
// This will the value 25 as the last point of Serie1
$DataSet->AddPoint(25);

// This will the value 2,4,9,5,1,0 as the last point of Serie1


$DataSet->AddPoint(array(2,4,9,5,1,0));

// This will the value 12 as the last point of Serie2


$DataSet->AddPoint(12,"Serie2");

// .. and add the desciption "March" to the Serie2


$DataSet->AddPoint(12,"Serie2","March");

AddSerie
void AddSerie($SerieName="Serie1")

This function can be used to add a new data serie to the DataDescription object. All the series
declared in this object will be graphed when calling a chart function of the pChart class. There is no
change on Data, only the "Graphable" attribute is modified.
1. // Generate some data...
2. $DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
3. $DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");
4. $DataSet->AddPoint(array(4,2,4,2,4,2),"Serie3");
5.
6. // This will mark both Serie1 & Serie2 as "graphable" but not Serie3
7. $DataSet->AddSerie("Serie1");
8. $DataSet->AddSerie("Serie2");
// Generate some data...
$DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
$DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");
$DataSet->AddPoint(array(4,2,4,2,4,2),"Serie3");

// This will mark both Serie1 & Serie2 as "graphable" but not Serie3
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");

AddAllSeries
void AddAllSeries()

This function can be used to set all data series as graphable. They'll all be graphed when calling a
chart function of the pChart class. There is no change on Data, only the "Graphable" attribute is
modified.
1. // Generate some data...
2. $DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
3. $DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");
4.
5. // This will mark both Serie1 & Serie2 as "graphable"
6. $DataSet->AddAllSeries();
// Generate some data...
$DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
$DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");

// This will mark both Serie1 & Serie2 as "graphable"


$DataSet->AddAllSeries();

RemoveSerie
void RemoveSerie($SerieName="Serie1")

This function can be used to remove a data series from the graphable ones. They'll all be graphed
when calling a chart function of the pChart class. There is no change on Data, only the "Graphable"
attribute is modified.
1. // Generate some data...
2. $DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
3. $DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");
4.
5. // This will mark both Serie1 & Serie2 as "graphable"
6. $DataSet->AddAllSeries();
7.
8. // This will remove the "graphable" status of Serie2
9. $DataSet->RemoveSerie("Serie2");
// Generate some data...
$DataSet->AddPoint(array(2,4,9,5,1,0),"Serie1");
$DataSet->AddPoint(array(1,1,2,2,3,3),"Serie2");

// This will mark both Serie1 & Serie2 as "graphable"


$DataSet->AddAllSeries();

// This will remove the "graphable" status of Serie2


$DataSet->RemoveSerie("Serie2");

SetAbsciseLabelSerie
void SetAbsciseLabelSerie($SerieName = "Name")

This function can be used to set which serie is used (if any) as abcisse value
1. // Generate some data...
2. $DataSet->AddPoint(array("Jan","Feb","Mar"),"Serie1");
3. $DataSet->AddPoint(array(2,4,9),"Serie2");
4. $DataSet->AddPoint(array(1,1,2),"Serie3");
5.
6. // This will mark both Serie1 & Serie2 as "graphable"
7. $DataSet->AddSerie("Serie2");
8. $DataSet->AddSerie("Serie3");
9.
10.// Set Serie as abcisse label
11.$DataSet->SetAbsciseLabelSerie("Serie1");
// Generate some data...
$DataSet->AddPoint(array("Jan","Feb","Mar"),"Serie1");
$DataSet->AddPoint(array(2,4,9),"Serie2");
$DataSet->AddPoint(array(1,1,2),"Serie3");

// This will mark both Serie1 & Serie2 as "graphable"


$DataSet->AddSerie("Serie2");
$DataSet->AddSerie("Serie3");

// Set Serie as abcisse label


$DataSet->SetAbsciseLabelSerie("Serie1");

SetSerieName
void SetSerieName($Name,$SerieName="Serie1")

This function can be used to set the description of a serie. This description will be written on the
graph when calling the drawLegend function
1. // Generate some data...
2. $DataSet->AddPoint(array(2,4,9),"Serie1");
3. $DataSet->AddPoint(array(1,1,2),"Serie2");
4.
5. // This will set the name of Serie1 to "January"
6. $DataSet->SetSerieName("January");
7.
8. // This will set the name of Serie2 to "February"
9. $DataSet->SetSerieName("February","Serie2");
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");

// This will set the name of Serie1 to "January"


$DataSet->SetSerieName("January");

// This will set the name of Serie2 to "February"


$DataSet->SetSerieName("February","Serie2");

SetXAxisName
void SetXAxisName($Name="X Axis")

This will give a name to the X axis, writting it horizontally behind the chart
1. // Give the label "Samples" to the X axis
2. $DataSet->SetXAxisName("Samples")
// Give the label "Samples" to the X axis
$DataSet->SetXAxisName("Samples")

SetYAxisName
void SetYAxisName($Name="Y Axis")

This will give a name to the Y axis, writting it horizontally behind the chart
1. // Give the label "Temperature" to the Y axis
2. $DataSet->SetYAxisName("Temperature")
// Give the label "Temperature" to the Y axis
$DataSet->SetYAxisName("Temperature")

SetXAxisFormat
void SetXAxisFormat($Format="number")

With this function you can set the format of the X axis values. Todays formats are the following :

- number used by defaults


- time amount of seconds will be displayed as HH:MM:SS
- date unix timestamp will be displayed as a date
- metric number that will be displayed with k/m/g units
- currency currency with custom unit
1. // Set X values format as date
2. $DataSet->SetXAxisFormat("date")
// Set X values format as date
$DataSet->SetXAxisFormat("date")

SetYAxisFormat
void SetYAxisFormat($Format="number")

With this function you can set the format of the Y axis values. Todays formats are the following :
- number used by defaults
- time amount of seconds will be displayed as HH:MM:SS
- date unix timestamp will be displayed as a date
- metric number that will be displayed with k/m/g units
- currency currency with custom unit
1. // Set Y values format as date
2. $DataSet->SetYAxisFormat("metric")
// Set Y values format as date
$DataSet->SetYAxisFormat("metric")

SetXAxisUnit
void SetXAxisUnit($Unit="")

Set the axis unit. This will be appended to the axis values.
1. // Give the "km" unit to the X axis
2. $DataSet->SetXAxisUnit("km")
// Give the "km" unit to the X axis
$DataSet->SetXAxisUnit("km")

SetYAxisUnit
void SetYAxisUnit($Unit="")

Set the axis unit. This will be appended to the axis values.
1. // Give the "m/s" unit to the Y axis
2. $DataSet->SetYAxisUnit("m/s")
// Give the "m/s" unit to the Y axis
$DataSet->SetYAxisUnit("m/s")

removeSerieName
void removeSerieName($SerieName)

This function can be used to remove the description of a serie. This description will be written on
the graph when calling the drawLegend function. Removing it's name using this function can be
usefull to hide previously used series ( to fill area for exemple )
1. // Generate some data...
2. $DataSet->AddPoint(array(2,4,9),"Serie1");
3. $DataSet->AddPoint(array(1,1,2),"Serie2");
4.
5. // This will set the name of Serie1 to "January"
6. $DataSet->SetSerieName("January");
7.
8. // This will set the name of Serie2 to "February"
9. $DataSet->SetSerieName("February","Serie2");
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");

// This will set the name of Serie1 to "January"


$DataSet->SetSerieName("January");

// This will set the name of Serie2 to "February"


$DataSet->SetSerieName("February","Serie2");

GetData
void GetData()

This function is used everytime you want to retrieve the Data stored in the pData structure
1. // Generate some data...
2. $DataSet->AddPoint(array(2,4,9),"Serie1");
3. $DataSet->AddPoint(array(1,1,2),"Serie2");
4.
5. // This will display all the data stored in the DataSet
6. print_r($DataSet->GetData());
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");

// This will display all the data stored in the DataSet


print_r($DataSet->GetData());

GetDataDescription
void GetDataDescription()

This function is used everytime you want to retrieve the Data description stored in the pData
structure
1. // Generate some data...
2. $DataSet->AddPoint(array(2,4,9),"Serie1");
3. $DataSet->AddPoint(array(1,1,2),"Serie2");
4.
5. // This will mark both Serie1 & Serie2 as "graphable"
6. $DataSet->AddAllSeries();
7.
8. // This will set the name of Serie1 to "January"
9. $DataSet->SetSerieName("January");
10.
11.// This will display all the data stored in the DataSet
12.print_r($DataSet->GetDataDescription());
// Generate some data...
$DataSet->AddPoint(array(2,4,9),"Serie1");
$DataSet->AddPoint(array(1,1,2),"Serie2");

// This will mark both Serie1 & Serie2 as "graphable"


$DataSet->AddAllSeries();

// This will set the name of Serie1 to "January"


$DataSet->SetSerieName("January");
// This will display all the data stored in the DataSet
print_r($DataSet->GetDataDescription());

pCache.class - Compute one time, spread everywhere

Saving web server speed and CPU is something that matter to us. We've created the pCache class to
help you dealing with the fact that a chart can be computed once and displayed many times by
different users. The pCache class can be used to simplify server side cache management. In green,
the normal process : retrieve data, compute and display, in orange the cost saving path, retrieve the
data, check if we have already computed it and display it!

An example of how to use the pCache class can be found here. You'll find bellow a short summary
of all the embeded function and their related parameters. Functions categories :

Class initialisation
pCache($CacheFolder="Cache/")
Cache management
IsInCache($ID,$Data,$Hash="")
GetFromCache($ID,$Data)
WriteToCache($ID,$Data,$Picture)
DeleteFromCache($ID,$Data)
DeleteFromCache()

pCache

void pCache($CacheFolder="Cache/")

This function create a new pCache object. This object will be used to access the processed data
cache. You can optionnaly specify the cache folder to use.

1. // This will create a new pCache object with default cache folder
2. $MyCache = new pCache();
3.
4. // This will create a new pCache object setting the cache folder to /tmp/
5. $MyCache = new pCache("/tmp/");
// This will create a new pCache object with default cache folder
$MyCache = new pCache();
// This will create a new pCache object setting the cache folder to /tmp/
$MyCache = new pCache("/tmp/");

IsInCache
void IsInCache($ID,$Data,$Hash="")

This function can be used to check if the dataseries you're currently working on has already been
computed and is stored in the cache. This will return TRUE or FALSE. This function accept a
Dataset as first parameter, see the pData class for more informations. ID is used to uniquely
indentify your drawing script.
1. // This will return TRUE if this chart has already been rendered
2. $MyCache->IsInCache("Pic#1",$DataSet->GetData());
// This will return TRUE if this chart has already been rendered
$MyCache->IsInCache("Pic#1",$DataSet->GetData());

GetFromCache
void GetFromCache($ID,$Data)

This function will retrieve a chart from the cache if it already exists. The picture will be sent to the
browser the same way as if you're invoking the Stroke() function of the pChart class. ID is used to
uniquely indentify your drawing script. If the cache can be used, the picture will be send to the
browser the same way then calling the Stroke() function, no other lines of your script will be
processed after this line.
1. // This will check the cache for an existing copy and Stroke it.
2. $MyCache->GetFromCache("Pic#1",$DataSet->GetData());
// This will check the cache for an existing copy and Stroke it.
$MyCache->GetFromCache("Pic#1",$DataSet->GetData());

WriteToCache
void WriteToCache($ID,$Data,$Picture)

Use this function to make a copy of the rendered chart to your cache folder. This function is
mandatory for the pCache to work properly. This function must be called at the end of your
rendering script before the Stroke() or Render() call. ID is used to uniquely indentify your drawing
script. $Data is the dataset used to draw the chart. $Picture is the name of the pChart object
containing the chart.
1. // This will save the rendered picture in the cache folder.
2. $MyCache->WriteToCache("Pic#1",$DataSet->GetData(),$Picture);
// This will save the rendered picture in the cache folder.
$MyCache->WriteToCache("Pic#1",$DataSet->GetData(),$Picture);

DeleteFromCache
void DeleteFromCache($ID,$Data)

This function can be used to delete the cached copy of the chart ( if it exists ). ID is used to
uniquely indentify your drawing script.
1. // This will delete any cached copy of this chart.
2. $MyCache->DeleteFromCache("Pic#1",$DataSet->GetData());
// This will delete any cached copy of this chart.
$MyCache->DeleteFromCache("Pic#1",$DataSet->GetData());

ClearCache
void ClearCache()

Calling this function will clear the cache folder.


1. // This will cleanup the cache folder.
2. $MyCache->ClearCache();
// This will cleanup the cache folder.
$MyCache->ClearCache();
Using pChart with MySQL

Most of the time the pChart library will be linked to a database in order to retrieve dynamic data.
This tutorial will show you how to use the pChart and the pData classes to adapt SQL results into
a graph. What is done here with MySQL can be easily reused for any kind of database engine like
MS SQL server or Oracle.

First of all, connect to your MySQL database:


view plaincopy to clipboardprint?

1. $db = mysql_connect("localhost", "username", "password");


2. if ( $db == "" ) { echo " DB Connection error...\r\n"; exit(); }
3.
4. mysql_select_db("mydatabase",$db);
$db = mysql_connect("localhost", "username", "password");
if ( $db == "" ) { echo " DB Connection error...\r\n"; exit(); }

mysql_select_db("mydatabase",$db);

This code will connect to the MySQL service running on the same server than the PHP script using
username / password credential. We're then setting the current database to mydatabase.
Retrieving graph data

The graph data will be first retrieved using an SQL query that will depends on your SQL scheme.
This simple example assume that the data is located in the column 'value' of the 'data' table. We're
also assuming that you are already connected with your database $db.
view plaincopy to clipboardprint?
1. $Requete = "SELECT `value` FROM `data`";
2. $result = mysql_query($Requete,$db);
3. while ($row = mysql_fetch_array($result))
4. { $DataSet->AddPoint($row["value"],"Serie1"); }
$Requete = "SELECT `value` FROM `data`";
$result = mysql_query($Requete,$db);
while ($row = mysql_fetch_array($result))
{ $DataSet->AddPoint($row["value"],"Serie1"); }

Of course it will be better to order your data if you have an index column (named 'id' here) :
view plaincopy to clipboardprint?
1. $Requete = "SELECT `value` FROM `data` ORDER BY `id`";
2. $result = mysql_query($Requete,$db);
3. while ($row = mysql_fetch_array($result))
4. { $DataSet->AddPoint($row["value"],"Serie1"); }
$Requete = "SELECT `value` FROM `data` ORDER BY `id`";
$result = mysql_query($Requete,$db);
while ($row = mysql_fetch_array($result))
{ $DataSet->AddPoint($row["value"],"Serie1"); }

You can retrieve many series in a single query :


view plaincopy to clipboardprint?
1. $Requete = "SELECT `value1`,`value2`,`value3` FROM `data` ORDER BY `id`";
2. $result = mysql_query($Requete,$db);
3. while ($row = mysql_fetch_array($result))
4. {
5. $DataSet->AddPoint($row["value1"],"Serie1");
6. $DataSet->AddPoint($row["value2"],"Serie2");
7. $DataSet->AddPoint($row["value3"],"Serie3");
8. }
$Requete = "SELECT `value1`,`value2`,`value3` FROM `data` ORDER BY `id`";
$result = mysql_query($Requete,$db);
while ($row = mysql_fetch_array($result))
{
$DataSet->AddPoint($row["value1"],"Serie1");
$DataSet->AddPoint($row["value2"],"Serie2");
$DataSet->AddPoint($row["value3"],"Serie3");
}

When you've retrieved your data, don't forget to mark all series as graphable :
view plaincopy to clipboardprint?
1. $DataSet->AddAllSeries();
$DataSet->AddAllSeries();

Other things to do...

Don't forget to set the series descriptions! This descriptions can come from an SQL query or be
statically set depending of your database content.

Statically :
view plaincopy to clipboardprint?
1. $DataSet->SetSerieName("Mydescription","Serie1");
$DataSet->SetSerieName("Mydescription","Serie1");

A simple way to deal with SQL should be something like :


view plaincopy to clipboardprint?
1. $Requete = "SELECT `description` FROM `datadescription` WHERE `serie`='Serie1'";
2. $result = mysql_query($Requete,$db);
3. $row = mysql_fetch_array($result);
4. $DataSet->SetSerieName($row["description"],"Serie1");
$Requete = "SELECT `description` FROM `datadescription` WHERE `serie`='Serie1'";
$result = mysql_query($Requete,$db);
$row = mysql_fetch_array($result);
$DataSet->SetSerieName($row["description"],"Serie1");

or a more interesting way :


view plaincopy to clipboardprint?
1. $Requete = "SELECT `description`,`serie` FROM `datadescription`";
2. $result = mysql_query($Requete,$db);
3. while ($row = mysql_fetch_array($result))
4. { $DataSet->SetSerieName($row["description"],$row["serie"]); }
$Requete = "SELECT `description`,`serie` FROM `datadescription`";
$result = mysql_query($Requete,$db);
while ($row = mysql_fetch_array($result))
{ $DataSet->SetSerieName($row["description"],$row["serie"]); }
..assuming you have a table named 'datadescription' containing two columns 'serie' and 'description'.
The 'serie' column containing the ID of the serie we've used while retrieving data : Serie1, Serie2,
Serie3 and the description containing the legend text associated.

Playing with colors

Finding the good colors to use in your graph is a tricky game. To help you dealing with color
palettes we're providing some extended schemes that you can download clicking on the Add-ons
link from this page top bar, then select color schemes. Basically pChart embed a 8 colors palette,
this means that if you do not change the color settings, series with an ID greater than 8 will be
shown as black. The pChart basic palette :

0 1 2 3 4 5 6 7

We'll show you here how to change one color or to bulk import a color scheme.
Changing the colors!

Let's first start by changing the existing palette. To do so the pChart class embed the
setColorPalette() function. This function is taking 4 arguments, the first one is the color ID. What
is important to understand here is that color ID start at 0 but series ID start at 1 : The color ID of the
first serie 'Serie1' will be 0!

To change the color of the first serie to red :


view plaincopy to clipboardprint?
1. setColorPalette(0,255,0,0);
setColorPalette(0,255,0,0);

To change the color of the third serie to blue :


view plaincopy to clipboardprint?
1. setColorPalette(2,0,0,255);
setColorPalette(2,0,0,255);

Colors are defined using their R,G,B composantes. To understand this way of computing colors you
can see this wikipedia article.
Loading a color scheme

If you don't want to write 10 times the setColorPalette() function you can load a color scheme from
a flat text file. This is a flexible way to manage color palette as the same scheme can be reused from
another pChart script. Modifying this scheme will also modify all script that are refering to it.

Basically a color scheme file is a text file with one R,G,B value per line. First line will be associated
to the first data serie. R,G,B value can be separated with a coma or another separator of your choice.

To make soft green tones, create a file named 'palette.txt' containing :


168,188,56
188,208,76
208,228,96
228,245,116
248,255,136

0 1 2 3 4

..and load it using (assuming you pChart object is named $Test) :


view plaincopy to clipboardprint?
1. $Test->loadColorPalette('palette.txt');
$Test->loadColorPalette('palette.txt');

If you've choosen another delimiter than the coma, set this separator character as the second
parameter of the loadColorPalette function call (here the delimiter will be the '¤' character) :
view plaincopy to clipboardprint?
1. $Test->loadColorPalette('palette.txt','¤');
$Test->loadColorPalette('palette.txt','¤');

Now you can play with color palettes!

Setting X Labels

It can be usefull / mandatory to define what will be the X labels displayed on the graphs (line,
curve, bar, ..). In a basic configuration we do not care of this, the pData class automaticaly create a
'Name' serie incrementing a value for each new point, in results, X labels are numeric values. It is
hopefully possible for you to manually define this labels creating a dedicated serie!

Create your X Labels data serie

The creation of this serie will be done exactly the same way you are creating your data series. You
can do this using different pData functions. Let's first try with the AddPoint method adding one
label per call :
view plaincopy to clipboardprint?

1. $DataSet->AddPoint("Jan","XLabel");
2. $DataSet->AddPoint("Feb","XLabel");
3. $DataSet->AddPoint("Mar","XLabel");
$DataSet->AddPoint("Jan","XLabel");
$DataSet->AddPoint("Feb","XLabel");
$DataSet->AddPoint("Mar","XLabel");

you can also use an array :


view plaincopy to clipboardprint?
1. $DataSet->AddPoint(array("Jan","Feb","Mar"),"XLabel");
$DataSet->AddPoint(array("Jan","Feb","Mar"),"XLabel");

We now have a data serie containing the labels.


Use a serie as X Labels
The pData class embed a function named SetAbsciseLabelSerie(). This method can be used to set
which serie will be used for X Labels. By default, calling it with no parameters will set the inbuild
'Name' serie to be used. To set the serie we've previously populated :
view plaincopy to clipboardprint?
1. $DataSet->SetAbsciseLabelSerie("XLabel");
$DataSet->SetAbsciseLabelSerie("XLabel");

Be careful if you are using the AddAllSeries to mark all your series as graphable. The XLabel serie
will also be drawn and we don't want that. You have two possibilies. First one would be to remove
this serie from the graphable list :
view plaincopy to clipboardprint?
1. $DataSet->RemoveSerie("XLabel");
$DataSet->RemoveSerie("XLabel");

The other solution would be to not use the AddAllSeries but add manually each series :
view plaincopy to clipboardprint?
1. $DataSet->AddSerie("Serie1");
2. $DataSet->AddSerie("Serie2");
3. $DataSet->AddSerie("Serie3");
4. ...
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->AddSerie("Serie3");

Series are drawn black?

No, this is not a bug! Series can be drawn as black in at least two circumstances.

You do not have enough colors in your palette

Everything is in the title! Remember, basically pChart embed only colors for 8 series. If you have
more than 8 series, you'll need to add colors to you palette. The setColorPalette() is here to help
you!
view plaincopy to clipboardprint?

1. setColorPalette(8,255,0,0);
2. setColorPalette(9,0,255,0);
3. setColorPalette(10,0,0,255);
setColorPalette(8,255,0,0);
setColorPalette(9,0,255,0);
setColorPalette(10,0,0,255);

you can also load a color scheme (assuming it contains enough colors!) :
view plaincopy to clipboardprint?
1. $Test->loadColorPalette('palette.txt');
$Test->loadColorPalette('palette.txt');

logical no?
Series descriptions are not set

This bug has been fixed since version 1.27

In order to keep the association between color ID and series in case you are dynamically removing
series (when using drawArea() for example) some drawing function needs that all serie have a
description. To add a description to one serie, use the SetSerieName() method from the pData
class :
view plaincopy to clipboardprint?
1. $DataSet->SetSerieName("January","Serie1");
2. $DataSet->SetSerieName("February","Serie2");
3. $DataSet->SetSerieName("March","Serie3");
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");
$DataSet->SetSerieName("March","Serie3");

not logical, I know.

Debugging charts

You'll probably face a day issues while drawing a chart. Since release 1.27, we've introduced error
pre-checking that is correcting common issues and the ability to report the error messages directly
on the console (for console called script or script that are using the Render() function to generate
image) or to print the messages over the generated pictures (for scripts that are sending the picture
directly to the user browser calling the Stroke() function).

To turn on error checking add the following call :


view plaincopy to clipboardprint?

1. $Test->ReportWarnings();
$Test->ReportWarnings();

Specifying no parameter will determine the output (Console/GD) depending on the renderin method
(Render/Stroke). You can force the reporting output specifying :
view plaincopy to clipboardprint?
1. /* This will print errors to the command line STDOUT */
2. $Test->ReportWarnings("CLI");
3.
4. /* This will print errors over the generated picture using GD */
5. $Test->ReportWarnings("GD");
/* This will print errors to the command line STDOUT */
$Test->ReportWarnings("CLI");

/* This will print errors over the generated picture using GD */


$Test->ReportWarnings("GD");

Debugging to the console

If you choose to send debugging informations to the console, you mustn't call the Stroke() function
as messages will be directly displayed to STDOUT by the pChart library breaking the picture. You'll
see a broken picture in your browser or a page of ununderstandable characters. A typical call will
display something like :
C:\Web\pChart>php -q Example19.php
[Warning] drawCubicCurve - Some series descriptions are not set.
[Warning] drawLegend - Some series descriptions are not set.

C:\Web\pChart>

Debugging using GD

If you are generating on-the-fly pictures it can be cool to integrate the error messages directly in the
rendered picture to see if something is going wrong. Messages will be written in a red box aligned
on the bottom-right corner of the pictures like in this example :

What is checked and fixed today

The following items are checked while calling scaling or chart-drawing functions

Data Structure
- Is there data in the series (no fix)
- Are the series containing the same amount of data (no fix)

DataDescription Structure
- Is there a serie associated to the Y labels (using serie "Name" as default)
- Do we have a description set for all series (using the serie name as default)

Call to undefined function imagecreatetruecolor()

This is probably the first error message that you can see while using pChart. Many PHP installations
are made without adding GD support. If GD isn't linked in your PHP setup you'll have this error
message :

C:\Web\pChart>php -q Example1.php
PHP Fatal error: Call to undefined function imagecreatetruecolor() in
C:\pChart.class on line 134

To activate GD support on windows systems edit your php.ini file (located in your php installation)
and uncomment this line :
;extension=php_gd2.dll
..by removing the ; character. If you are running a linux installation of PHP, you must recompile it
including GD support, you'll also need to include the FreeType support. We invite you to read the
PHP manual.
How to check your PHP setup

To see the configuration of PHP on your web server, make a file named test.php in the web
directory root and write the following in it :
view plaincopy to clipboardprint?
1. <?php
2. phpinfo();
3. ?>
<?php
phpinfo();
?>

..then open this page in a web browser and locate the GD part :
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.1.9

pChart needs that both GD and FreeType support are enabled.

Data Structure

It is important for you to understand how to interface your data with the pChart library. To help you
dealing with points and serie, I've made the pData class. You're free to use it or not! Sometimes it
can be easier to directly create the Data & DataDescription arrays. This is a short summary on how
the data are structured.

Data array

This array contains all series and associated data. The fisrt key should be kept as numeric and
lineary incremented.

Array
(
[0] => Array
(
[Name] => January
[Serie1] => 0
[Serie2] => 1
)

[1] => Array


(
[Name] => February
[Serie1] => 1
[Serie2] => 4
)
[2] => Array
(
[Name] => March
[Serie1] => 4
[Serie2] => 9
)
)

To rawly generate this array you can proceed this way :


1. $Data[] = array("Name"=>"January","Serie1"=>0,"Serie2"=>1);
2. $Data[] = array("Name"=>"February","Serie1"=>1,"Serie2"=>4);
3. $Data[] = array("Name"=>"March","Serie1"=>4,"Serie2"=>9);
$Data[] = array("Name"=>"January","Serie1"=>0,"Serie2"=>1);
$Data[] = array("Name"=>"February","Serie1"=>1,"Serie2"=>4);
$Data[] = array("Name"=>"March","Serie1"=>4,"Serie2"=>9);

You can also do this way :


1. $Data[0]["Name"] = "January";
2. $Data[0]["Serie1"] = 0;
3. $Data[0]["Serie2"] = 1;
4. $Data[1]["Name"] = "February";
5.
6. /* ... */
$Data[0]["Name"] = "January";
$Data[0]["Serie1"] = 0;
$Data[0]["Serie2"] = 1;
$Data[1]["Name"] = "February";

/* ... */

Data Description array

This array contains informations about the series : which ones will be displayed on graphs, their
name, which serie to use as abscissa data.
Array
(
[Position] => Name
[Values] => Array
(
[0] => Serie1
[1] => Serie2
)

[Description] => Array


(
[Serie1] => Year 2007
[Serie2] => Year 2008
)

$DataDescription["Position"] contains the name of the serie to use as abscissa data.


$DataDescription["Values"] contains the list of the series that will be displayed when calling a
graph function of the pChart library. $DataDescription["Description"][
1.

Good luck with your data transformation!

Running from CLI - Command Line Interface

Taking in consideration the amount of ressources needed to build a picture with PHP, it can be wise
to schedule the creation of the graphs on a periodic basis. Doing this way will prevent hanging the
apache ( or whatever web server ) process. This documentation explains how to use PHP from the
command line & how to schedule a task from Windows or Linux ( using crontab )

Running PHP from the command line interface

PHP can be run from the command line interface of all operating systems. Putting the php binary
folder in your system path variable can be extremely wise!

To display the version of your PHP binary you can use the php -v command.

Z:\>php -v
PHP 5.2.5 (cli) (built: Nov 8 2007 23:18:51)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

[ayashisunyday@pr-shellC ~]$ php -v


PHP 4.3.9 (cgi) (built: Feb 21 2007 06:35:52)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

To run a PHP script from the command line you can use the following syntax :
Z:\>php -q MyScript.php

You can also redirect the output of this command to a log file : To run a PHP script from the
command line you can use the following syntax :
Z:\>php -q MyScript.php >messages.log

Scheduling a PHP script from Linux


To schedule a job on linux ( assuming the crontab package is installed ) I recommand you to create
a bash file starting the PHP script and a cron task running this bash file. Doing this way you'll be
able to change the PHP stuff without modifying your cron job.

Create a text file called run with the following content :


/usr/local/php4/bin/php -q MyScript.php
/usr/local/php4/bin/php -q MyScript2.php

.. containing all of the PHP script you want to start. Then make this file executable :
chmod +x run

Now you can add this script in your crontab :


crontab -e

.. and put the following content :


30 04 * * * /path/to/run >>/var/log/php-scripts.log

.. and exit the text editor. The crontab will be installed on the system. You may need to restart the
crontab daemon :
/etc/init.d/cron restart
.. or ( depending on the daemon you are using )
/etc/init.d/vixie-cron restart

Using 30 04 * * * will start the job every day at 04:30. to run a scrip every ten minutes you can use
10 * * * *. To have more infos on the crontab command take a look here.
Scheduling a PHP script from Windows

To schedule a job on windows, I recommand you to create a batch file starting the PHP script and
an at task running this command file. Doing this way you'll be able to change the PHP stuff without
modifying your task.

Create a text file called run.cmd with the following content :


php -q MyScript.php
php -q MyScript2.php

.. containing all of the PHP script you want to start. Now you can add this command file to your
scheduled tasks :
at 20:30 /every:M,T,W,Th,F,S,Su run.cmd

This will start your task every day at 20:30. To have more infos dealing with the AT command you
can take a look on this : How To Use the AT Command to Schedule Tasks.

You can also use the Windows graphical interface by going in the Control Panel & use the
Scheduled task manager.
Example #1 - Creating a line graph

This example shows how to create a simple line graph containing 3 data series. The graph function
called is drawLineGraph() without extended parameters. A plot graph is superposed over the line
layer using the drawPlotGraph() function. Running this script will create a example1.png file in the
current directory.

Output :

Note on the dataset

Data are retrieved from a CSV file named bulkdata.csv. This file contains 4 colums : Column 0 is
used as index, Column 1-2-3 are used as data series. This file does not contains header, Series name
are set manualy using the SetSerieName command.
Click here to download bulkdata.csv

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->ImportFromCSV("Sample/bulkdata.csv",",",array(1,2,3),FALSE,0);
9. $DataSet->AddAllSeries();
10. $DataSet->SetAbsciseLabelSerie();
11. $DataSet->SetSerieName("January","Serie1");
12. $DataSet->SetSerieName("February","Serie2");
13. $DataSet->SetSerieName("March","Serie3");
14. $DataSet->SetYAxisName("Average age");
15. $DataSet->SetYAxisUnit("µs");
16.
17. // Initialise the graph
18. $Test = new pChart(700,230);
19. $Test->setFontProperties("Fonts/tahoma.ttf",8);
20. $Test->setGraphArea(70,30,680,200);
21. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
22. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
23. $Test->drawGraphArea(255,255,255,TRUE);
24. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
25. $Test->drawGrid(4,TRUE,230,230,230,50);
26.
27. // Draw the 0 line
28. $Test->setFontProperties("Fonts/tahoma.ttf",6);
29. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
30.
31. // Draw the line graph
32. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
33. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
34.
35. // Finish the graph
36. $Test->setFontProperties("Fonts/tahoma.ttf",8);
37. $Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255);
38. $Test->setFontProperties("Fonts/tahoma.ttf",10);
39. $Test->drawTitle(60,22,"example 1",50,50,50,585);
40. $Test->Render("example1.png");
41.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->ImportFromCSV("Sample/bulkdata.csv",",",array(1,2,3),FALSE,0);
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");
$DataSet->SetSerieName("March","Serie3");
$DataSet->SetYAxisName("Average age");
$DataSet->SetYAxisUnit("µs");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(70,30,680,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"example 1",50,50,50,585);
$Test->Render("example1.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #2 - Creating a cubic curve graph

This example shows how to create a simple cubic curve graph containing two data series. Data are
manualy set using the AddPoint() method of the pData class. The graph function called is
drawCubicCurve() without extended parameters. Running this script will create a example2.png file
in the current directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,3,4,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
9. $DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie();
12. $DataSet->SetSerieName("January","Serie1");
13. $DataSet->SetSerieName("February","Serie2");
14.
15. // Initialise the graph
16. $Test = new pChart(700,230);
17. $Test->setFixedScale(-2,8);
18. $Test->setFontProperties("Fonts/tahoma.ttf",8);
19. $Test->setGraphArea(50,30,585,200);
20. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
21. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
22. $Test->drawGraphArea(255,255,255,TRUE);
23. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
24. $Test->drawGrid(4,TRUE,230,230,230,50);
25.
26. // Draw the 0 line
27. $Test->setFontProperties("Fonts/tahoma.ttf",6);
28. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
29.
30. // Draw the cubic curve graph
31. $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
32.
33. // Finish the graph
34. $Test->setFontProperties("Fonts/tahoma.ttf",8);
35. $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
36. $Test->setFontProperties("Fonts/tahoma.ttf",10);
37. $Test->drawTitle(50,22,"Example 1",50,50,50,585);
38. $Test->Render("example2.png");
39.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,3,4,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
$DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFixedScale(-2,8);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,585,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the cubic curve graph
$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 1",50,50,50,585);
$Test->Render("example2.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #13 - Creating a bar graph

This example shows how to create a simple bar graph containing three data series. Data are
manualy set using the AddPoint() method of the pData class. The graph function called is
drawBarGraph() setting the shadow drawing to TRUE. When doing bar graph, be sure to scale it
setting the $WithMargin parameter of the drawScale() function to TRUE. parameters. Running this
script will create a example12.png file in the current directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1");
9. $DataSet->AddPoint(array(3,3,-4,1,-2,2,1,0,-1,6,3),"Serie2");
10. $DataSet->AddPoint(array(4,1,2,-1,-4,-2,3,2,1,2,2),"Serie3");
11. $DataSet->AddAllSeries();
12. $DataSet->SetAbsciseLabelSerie();
13. $DataSet->SetSerieName("January","Serie1");
14. $DataSet->SetSerieName("February","Serie2");
15. $DataSet->SetSerieName("March","Serie3");
16.
17. // Initialise the graph
18. $Test = new pChart(700,230);
19. $Test->setFontProperties("Fonts/tahoma.ttf",8);
20. $Test->setGraphArea(50,30,680,200);
21. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
22. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
23. $Test->drawGraphArea(255,255,255,TRUE);
24. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);
25. $Test->drawGrid(4,TRUE,230,230,230,50);
26.
27. // Draw the 0 line
28. $Test->setFontProperties("Fonts/tahoma.ttf",6);
29. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
30.
31. // Draw the bar graph
32. $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);
33.
34. // Finish the graph
35. $Test->setFontProperties("Fonts/tahoma.ttf",8);
36. $Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255);
37. $Test->setFontProperties("Fonts/tahoma.ttf",10);
38. $Test->drawTitle(50,22,"Example 12",50,50,50,585);
39. $Test->Render("example12.png");
40.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1");
$DataSet->AddPoint(array(3,3,-4,1,-2,2,1,0,-1,6,3),"Serie2");
$DataSet->AddPoint(array(4,1,2,-1,-4,-2,3,2,1,2,2),"Serie3");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");
$DataSet->SetSerieName("March","Serie3");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,680,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);
$Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line
$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the bar graph


$Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 12",50,50,50,585);
$Test->Render("example12.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #21 - Creating a stacked bar graph

This example shows how to create a simple stacked bar graph containing three data series. Data are
manualy set using the AddPoint() method of the pData class. The graph function called is
drawStackedBarGraph(). When doing bar graph, be sure to scale it setting the $WithMargin
parameter of the drawScale() function to TRUE and the Scale mode to SCALE_ADDALL to get the
correct maximum value. Running this script will create a example12.png file in the current
directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1");
9. $DataSet->AddPoint(array(3,3,-4,1,-2,2,1,0,-1,6,3),"Serie2");
10. $DataSet->AddPoint(array(4,1,2,-1,-4,-2,3,2,1,2,2),"Serie3");
11. $DataSet->AddAllSeries();
12. $DataSet->SetAbsciseLabelSerie();
13. $DataSet->SetSerieName("January","Serie1");
14. $DataSet->SetSerieName("February","Serie2");
15. $DataSet->SetSerieName("March","Serie3");
16.
17. // Initialise the graph
18. $Test = new pChart(700,230);
19. $Test->setFontProperties("Fonts/tahoma.ttf",8);
20. $Test->setGraphArea(50,30,680,200);
21. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
22. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
23. $Test->drawGraphArea(255,255,255,TRUE);
24. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_ADDALL,150,150,150,TRUE,0,2,TRUE);
25. $Test->drawGrid(4,TRUE,230,230,230,50);
26.
27. // Draw the 0 line
28. $Test->setFontProperties("Fonts/tahoma.ttf",6);
29. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
30.
31. // Draw the bar graph
32. $Test->drawStackedBarGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),TRUE);
33.
34. // Finish the graph
35. $Test->setFontProperties("Fonts/tahoma.ttf",8);
36. $Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255);
37. $Test->setFontProperties("Fonts/tahoma.ttf",10);
38. $Test->drawTitle(50,22,"Example 20",50,50,50,585);
39. $Test->Render("example20.png");
40.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4),"Serie1");
$DataSet->AddPoint(array(3,3,-4,1,-2,2,1,0,-1,6,3),"Serie2");
$DataSet->AddPoint(array(4,1,2,-1,-4,-2,3,2,1,2,2),"Serie3");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");
$DataSet->SetSerieName("March","Serie3");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,680,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_ADDALL,150,150,150,TRUE,0,2,TRUE);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the bar graph


$Test->drawStackedBarGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),TRUE);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(596,150,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 20",50,50,50,585);
$Test->Render("example20.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #3 - Creating an overlay bar graph

This example shows how to create a simple bar graph containing two data series. Data are manualy
set using the AddPoint() method of the pData class. The graph function called is drawBarGraph()
without extended parameters. Running this script will create a example3.png file in the current
directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1");
9. $DataSet->AddPoint(array(0,3,-4,1,-2,2,1,0,-1,6,3,-4,1,-4,2,4,0,-1,6),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie();
12. $DataSet->SetSerieName("January","Serie1");
13. $DataSet->SetSerieName("February","Serie2");
14.
15. // Initialise the graph
16. $Test = new pChart(700,230);
17. $Test->setFontProperties("Fonts/tahoma.ttf",8);
18. $Test->setGraphArea(50,30,585,200);
19. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
20. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
21. $Test->drawGraphArea(255,255,255,TRUE);
22. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
23. $Test->drawGrid(4,TRUE,230,230,230,50);
24.
25. // Draw the 0 line
26. $Test->setFontProperties("Fonts/tahoma.ttf",6);
27. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
28.
29. // Draw the bar graph
30. $Test->drawOverlayBarGraph($DataSet->GetData(),$DataSet->GetDataDescription());
31.
32. // Finish the graph
33. $Test->setFontProperties("Fonts/tahoma.ttf",8);
34. $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
35. $Test->setFontProperties("Fonts/tahoma.ttf",10);
36. $Test->drawTitle(50,22,"Example 3",50,50,50,585);
37. $Test->Render("example3.png");
38.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1");
$DataSet->AddPoint(array(0,3,-4,1,-2,2,1,0,-1,6,3,-4,1,-4,2,4,0,-
1,6),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,585,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the bar graph


$Test->drawOverlayBarGraph($DataSet->GetData(),$DataSet-
>GetDataDescription());

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 3",50,50,50,585);
$Test->Render("example3.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #4 - Creating a line graph with a greyed area

This example shows how to create a line graph on top of a greyed area. To achieve this example we
need to have 3 data series : 2 are used for the max/min values of the area and 1 for the line graph
itself. The area is drawn using the drawArea() function giving the color & the alpha transparency
level. To draw only one serie calling the drawLineGraph() we must first remove the 2 others used
by the area with the RemoveSerie() function. The graph function called is drawBarGraph() without
extended parameters. Running this script will create a example4.png file in the current directory.

Output :

Note on the dataset

Data are retrieved from a CSV file named datawithtitle.csv. This file contains 4 colums : Column 0
is used as index, Column 1-2-3 are used as data series. This file does contains a header defining
series name.
Click here to download datawithtitle.csv

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->ImportFromCSV("Sample/datawithtitle.csv",",",array(1,2,3),TRUE,0);
9. $DataSet->AddSerie("Serie2");
10. $DataSet->SetAbsciseLabelSerie();
11. $DataSet->removeSerieName("Serie1");
12. $DataSet->removeSerieName("Serie3");
13.
14. // Initialise the graph
15. $Test = new pChart(700,230);
16. $Test->setFontProperties("Fonts/tahoma.ttf",8);
17. $Test->setGraphArea(60,30,680,200);
18. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
19. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
20. $Test->drawGraphArea(255,255,255,TRUE);
21. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
22. $Test->drawGrid(4,TRUE,230,230,230,50);
23.
24. // Draw the 0 line
25. $Test->setFontProperties("Fonts/tahoma.ttf",6);
26. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
27.
28. // Draw the area
29. $Test->drawArea($DataSet->GetData(),"Serie1","Serie3",239,238,227,50);
30.
31. // Draw the line graph
32. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
33. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
34.
35. // Finish the graph
36. $Test->setFontProperties("Fonts/tahoma.ttf",8);
37. $Test->drawLegend(65,35,$DataSet->GetDataDescription(),250,250,250);
38. $Test->setFontProperties("Fonts/tahoma.ttf",10);
39. $Test->drawTitle(60,22,"Example 4",50,50,50,585);
40. $Test->Render("example4.png");
41.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");
// Dataset definition
$DataSet = new pData;
$DataSet->ImportFromCSV("Sample/datawithtitle.csv",",",array(1,2,3),TRUE,0);
$DataSet->AddSerie("Serie2");
$DataSet->SetAbsciseLabelSerie();
$DataSet->removeSerieName("Serie1");
$DataSet->removeSerieName("Serie3");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(60,30,680,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the area


$Test->drawArea($DataSet->GetData(),"Serie1","Serie3",239,238,227,50);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(65,35,$DataSet->GetDataDescription(),250,250,250);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"Example 4",50,50,50,585);
$Test->Render("example4.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #5 - Creating a limits graph

This example shows how to create a simple limits graph containing two data series. Data are
manualy set using the AddPoint() method of the pData class. The graph function called is
drawLimitsGraph() specifying the color of the vertical line. Running this script will create a
example5.png file in the current directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1");
9. $DataSet->AddPoint(array(2,5,7,5,1,5,6,4,8,4,0,2,5,6,4,5,6,7,6),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie();
12. $DataSet->SetSerieName("January","Serie1");
13. $DataSet->SetSerieName("February","Serie2");
14.
15. // Initialise the graph
16. $Test = new pChart(700,230);
17. $Test->setFontProperties("Fonts/tahoma.ttf",8);
18. $Test->setGraphArea(50,30,585,200);
19. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
20. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
21. $Test->drawGraphArea(255,255,255,TRUE);
22. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
23. $Test->drawGrid(4,TRUE,230,230,230,50);
24.
25. // Draw the 0 line
26. $Test->setFontProperties("Fonts/tahoma.ttf",6);
27. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
28.
29. // Draw the limit graph
30. $Test->drawLimitsGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),180,180,180);
31.
32. // Finish the graph
33. $Test->setFontProperties("Fonts/tahoma.ttf",8);
34. $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
35. $Test->setFontProperties("Fonts/tahoma.ttf",10);
36. $Test->drawTitle(50,22,"Example 5",50,50,50,585);
37. $Test->Render("example5.png");
38.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1");
$DataSet->AddPoint(array(2,5,7,5,1,5,6,4,8,4,0,2,5,6,4,5,6,7,6),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,585,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the limit graph


$Test->drawLimitsGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),180,180,180);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 5",50,50,50,585);
$Test->Render("example5.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #6 - Creating a filled line graph with transparency

This example shows how to create a simple line graph containing 3 data series. The graph function
called is drawFilledLineGraph() specifying a transparency factor of 50%. Running this script will
create a example6.png file in the current directory.

Output :

Note on the dataset

Data are retrieved from a CSV file named datawithtitle.csv. This file contains 4 colums : Column 0
is used as index, Column 1-2-3 are used as data series. This file does contains a header defining
series name.
Click here to download datawithtitle.csv

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->ImportFromCSV("Sample/datawithtitle.csv",",",array(1,2,3),TRUE,0);
9. $DataSet->AddAllSeries();
10. $DataSet->SetAbsciseLabelSerie();
11.
12. // Initialise the graph
13. $Test = new pChart(700,230);
14. $Test->setFontProperties("Fonts/tahoma.ttf",8);
15. $Test->setGraphArea(60,30,680,200);
16. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
17. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
18. $Test->drawGraphArea(255,255,255,TRUE);
19. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
20. $Test->drawGrid(4,TRUE,230,230,230,50);
21.
22. // Draw the 0 line
23. $Test->setFontProperties("Fonts/tahoma.ttf",6);
24. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
25.
26. // Draw the filled line graph
27. $Test->drawFilledLineGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),50,TRUE);
28.
29. // Finish the graph
30. $Test->setFontProperties("Fonts/tahoma.ttf",8);
31. $Test->drawLegend(65,35,$DataSet->GetDataDescription(),255,255,255);
32. $Test->setFontProperties("Fonts/tahoma.ttf",10);
33. $Test->drawTitle(60,22,"Example 6",50,50,50,585);
34. $Test->Render("example6.png");
35.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->ImportFromCSV("Sample/datawithtitle.csv",",",array(1,2,3),TRUE,0);
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(60,30,680,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the filled line graph


$Test->drawFilledLineGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),50,TRUE);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(65,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"Example 6",50,50,50,585);
$Test->Render("example6.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #7 - Creating a filled cubic curve graph

This example shows how to create a simple cubic curve graph containing two data series. Data are
manualy set using the AddPoint() method of the pData class. The graph function called is
drawFilledCubicCurve() specifying a precision of .1 and a transparency factor of 50%. Running
this script will create a example7.png file in the current directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
9. $DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie();
12. $DataSet->SetSerieName("January","Serie1");
13. $DataSet->SetSerieName("February","Serie2");
14.
15. // Initialise the graph
16. $Test = new pChart(700,230);
17. $Test->setFontProperties("Fonts/tahoma.ttf",8);
18. $Test->setGraphArea(50,30,585,200);
19. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
20. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
21. $Test->drawGraphArea(255,255,255,TRUE);
22. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
23. $Test->drawGrid(4,TRUE,230,230,230,50);
24.
25. // Draw the 0 line
26. $Test->setFontProperties("Fonts/tahoma.ttf",6);
27. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
28.
29. // Draw the cubic curve graph
30. $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet-
>GetDataDescription(),.1,50);
31.
32. // Finish the graph
33. $Test->setFontProperties("Fonts/tahoma.ttf",8);
34. $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
35. $Test->setFontProperties("Fonts/tahoma.ttf",10);
36. $Test->drawTitle(50,22,"Example 7",50,50,50,585);
37. $Test->Render("example7.png");
38.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
$DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,585,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the cubic curve graph


$Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet-
>GetDataDescription(),.1,50);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 7",50,50,50,585);
$Test->Render("example7.png");
?>
If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #8 - Creating a filled radar graph

This example shows how to create a simple


filled radar graph containing two data series.
Data are manualy set using the AddPoint()
method of the pData class.

The first step consist in calling the


drawRadarAxis() function to prepare the graph
area by drawing the Axis. You can specify the
MaxValue or keep the automatic scaling mode.

The first step consist in calling the


drawFilledRadar() function to draw the radar
graph over the Axis layer with a transparency of
60%. ( default is 50% )

Running this script will create a example8.png


file in the current directory.

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array("Memory","Disk","Network","Slots","CPU"),"Label");
9. $DataSet->AddPoint(array(1,2,3,4,3),"Serie1");
10. $DataSet->AddPoint(array(1,4,2,6,2),"Serie2");
11. $DataSet->AddSerie("Serie1");
12. $DataSet->AddSerie("Serie2");
13. $DataSet->SetAbsciseLabelSerie("Label");
14.
15.
16. $DataSet->SetSerieName("Reference","Serie1");
17. $DataSet->SetSerieName("Tested computer","Serie2");
18.
19. // Initialise the graph
20. $Test = new pChart(400,400);
21. $Test->setFontProperties("Fonts/tahoma.ttf",8);
22. $Test->drawFilledRoundedRectangle(7,7,393,393,5,240,240,240);
23. $Test->drawRoundedRectangle(5,5,395,395,5,230,230,230);
24. $Test->setGraphArea(30,30,370,370);
25. $Test->drawFilledRoundedRectangle(30,30,370,370,5,255,255,255);
26. $Test->drawRoundedRectangle(30,30,370,370,5,220,220,220);
27.
28. // Draw the radar graph
29. $Test->drawRadarAxis($DataSet->GetData(),$DataSet-
>GetDataDescription(),TRUE,20,120,120,120,230,230,230);
30. $Test->drawFilledRadar($DataSet->GetData(),$DataSet->GetDataDescription(),50,20);
31.
32. // Finish the graph
33. $Test->drawLegend(15,15,$DataSet->GetDataDescription(),255,255,255);
34. $Test->setFontProperties("Fonts/tahoma.ttf",10);
35. $Test->drawTitle(0,22,"Example 8",50,50,50,400);
36. $Test->Render("example8.png");
37.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array("Memory","Disk","Network","Slots","CPU"),"Label");
$DataSet->AddPoint(array(1,2,3,4,3),"Serie1");
$DataSet->AddPoint(array(1,4,2,6,2),"Serie2");
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetAbsciseLabelSerie("Label");

$DataSet->SetSerieName("Reference","Serie1");
$DataSet->SetSerieName("Tested computer","Serie2");

// Initialise the graph


$Test = new pChart(400,400);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawFilledRoundedRectangle(7,7,393,393,5,240,240,240);
$Test->drawRoundedRectangle(5,5,395,395,5,230,230,230);
$Test->setGraphArea(30,30,370,370);
$Test->drawFilledRoundedRectangle(30,30,370,370,5,255,255,255);
$Test->drawRoundedRectangle(30,30,370,370,5,220,220,220);

// Draw the radar graph


$Test->drawRadarAxis($DataSet->GetData(),$DataSet-
>GetDataDescription(),TRUE,20,120,120,120,230,230,230);
$Test->drawFilledRadar($DataSet->GetData(),$DataSet-
>GetDataDescription(),50,20);

// Finish the graph


$Test->drawLegend(15,15,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(0,22,"Example 8",50,50,50,400);
$Test->Render("example8.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #15 - Basic Pie graphs

Pie chart are slightly differents than classical line / curve / plot chart.

First of all they can only accept one serie of data ( Serie1 in this
example ). You can also specify in another serie the label associated to
each points ( Serie2 in this example ). In this example we're manually
feeding the series using the AddPoint() method of the pData class.
Then we're associating Serie2 as the Abscise serie using the
SetAbsciseLabelSerie() function. We're then calling the
drawBasicPieGraph() and drawPieLegend() functions to draw the
graph. We're drawing a shadow behind the graph by calling the
drawFilledCircle functions to draw a filled circle with a (+2,+2)
offset.

Running this script will create a example14.png file in the current


directory.

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
9. $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie("Serie2");
12.
13. // Initialise the graph
14. $Test = new pChart(300,200);
15. $Test->loadColorPalette("Sample/softtones.txt");
16. $Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);
17. $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230);
18.
19. // This will draw a shadow under the pie chart
20. $Test->drawFilledCircle(122,102,70,200,200,200);
21.
22. // Draw the pie chart
23. $Test->setFontProperties("Fonts/tahoma.ttf",8);
24. $Test->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218);
25. $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet-
>GetDataDescription(),250,250,250);
26.
27. $Test->Render("example14.png");
28.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
$DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");

// Initialise the graph


$Test = new pChart(300,200);
$Test->loadColorPalette("Sample/softtones.txt");
$Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);
$Test->drawRoundedRectangle(5,5,295,195,5,230,230,230);

// This will draw a shadow under the pie chart


$Test->drawFilledCircle(122,102,70,200,200,200);

// Draw the pie chart


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawBasicPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),120,100,70,PIE_PERCENTAGE,255,255,218);
$Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet-
>GetDataDescription(),250,250,250);

$Test->Render("example14.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #11 - Exploded Flat Pie graphs

Pie chart are slightly differents than classical line / curve / plot chart.

First of all they can only accept one serie of data ( Serie1 in this
example ). You can also specify in another serie the label associated to
each points ( Serie2 in this example ). In this example we're manually
feeding the series using the AddPoint() method of the pData class.
Then we're associating Serie2 as the Abscise serie using the
SetAbsciseLabelSerie() function. We're then calling the
drawFlatPieGraphWithShadow() and drawPieLegend() functions to
draw the graph. Shadow parameters are set using the
setShadowProperties() function.

Running this script will create a example13.png file in the current


directory.

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
9. $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie("Serie2");
12.
13. // Initialise the graph
14. $Test = new pChart(300,200);
15. $Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);
16. $Test->drawRoundedRectangle(5,5,295,195,5,230,230,230);
17.
18. // Draw the pie chart
19. $Test->setFontProperties("Fonts/tahoma.ttf",8);
20. $Test->setShadowProperties(2,2,200,200,200);
21. $Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet-
>GetDataDescription(),120,100,60,PIE_PERCENTAGE,10);
22. $Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet-
>GetDataDescription(),250,250,250);
23.
24. $Test->Render("example13.png");
25.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
$DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");

// Initialise the graph


$Test = new pChart(300,200);
$Test->drawFilledRoundedRectangle(7,7,293,193,5,240,240,240);
$Test->drawRoundedRectangle(5,5,295,195,5,230,230,230);

// Draw the pie chart


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setShadowProperties(2,2,200,200,200);
$Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet-
>GetDataDescription(),120,100,60,PIE_PERCENTAGE,10);
$Test->drawPieLegend(230,15,$DataSet->GetData(),$DataSet-
>GetDataDescription(),250,250,250);

$Test->Render("example13.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #11 - Pie graphs

Pie chart are slightly differents than classical line /


curve / plot chart.

First of all they can only accept one serie of data (


Serie1 in this example ). You can also specify in
another serie the label associated to each points (
Serie2 in this example ). In this example we're
manually feeding the series using the AddPoint()
method of the pData class. Then we're associating
Serie2 as the Abscise serie using the
SetAbsciseLabelSerie() function. We're then calling
the drawPieGraph() and drawPieLegend() functions
to draw the graph.

Running this script will create a example10.png file


in the current directory.

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
9. $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie("Serie2");
12.
13. // Initialise the graph
14. $Test = new pChart(380,200);
15. $Test->drawFilledRoundedRectangle(7,7,373,193,5,240,240,240);
16. $Test->drawRoundedRectangle(5,5,375,195,5,230,230,230);
17.
18. // Draw the pie chart
19. $Test->setFontProperties("Fonts/tahoma.ttf",8);
20. $Test->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,90,110,PIE_PERCENTAGE,TRUE,50,20,5);
21. $Test->drawPieLegend(310,15,$DataSet->GetData(),$DataSet-
>GetDataDescription(),250,250,250);
22.
23. $Test->Render("example10.png");
24.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(10,2,3,5,3),"Serie1");
$DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May"),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");

// Initialise the graph


$Test = new pChart(380,200);
$Test->drawFilledRoundedRectangle(7,7,373,193,5,240,240,240);
$Test->drawRoundedRectangle(5,5,375,195,5,230,230,230);

// Draw the pie chart


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawPieGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),150,90,110,PIE_PERCENTAGE,TRUE,50,20,5);
$Test->drawPieLegend(310,15,$DataSet->GetData(),$DataSet-
>GetDataDescription(),250,250,250);

$Test->Render("example10.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #25 - Scatter charts

Like the pie charts, scatter charts require a special use of the pData
class.

To draw a scatter plot you need to define at least two data serie. In this
exemple Serie1/Serie2 will be drawn as line. Data are filled using
some maths functions (cos/sin) to render circles. We'll keep the
scaling dynamic.

Before rendering a scatter chart you must invoke the drawXYScale()


function that will create both X and Y axis. By default, min/max
values will be retrieved from the series, anyway you can fix the values
while calling the setFixedScale function (not shown in this example) :
We can creating a box (-25,25)-(25,25) with 5 vertical and horizontal
divisions.

To draw the line scatter chart we are calling the drawXYGraph


function specifying the series name and the 1st palette color.

Running this script will create a example24.png file in the current


directory.

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8.
9. // Compute the points
10. for($i=0;$i<=360;$i=$i+10)
11. {
12. $DataSet->AddPoint(cos($i*3.14/180)*80+$i,"Serie1");
13. $DataSet->AddPoint(sin($i*3.14/180)*80+$i,"Serie2");
14. }
15.
16. $DataSet->SetSerieName("Trigonometric function","Serie1");
17. $DataSet->AddSerie("Serie1");
18. $DataSet->AddSerie("Serie2");
19. $DataSet->SetXAxisName("X Axis");
20. $DataSet->SetYAxisName("Y Axis");
21.
22. // Initialise the graph
23. $Test = new pChart(300,300);
24. $Test->drawGraphAreaGradient(0,0,0,-100,TARGET_BACKGROUND);
25.
26. // Prepare the graph area
27. $Test->setFontProperties("Fonts/tahoma.ttf",8);
28. $Test->setGraphArea(55,30,270,230);
29. $Test->drawXYScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie1","Serie2",213,217,221,TRUE,45);
30. $Test->drawGraphArea(213,217,221,FALSE);
31. $Test->drawGraphAreaGradient(30,30,30,-50);
32. $Test->drawGrid(4,TRUE,230,230,230,20);
33.
34. // Draw the chart
35. $Test->setShadowProperties(2,2,0,0,0,60,4);
36. $Test->drawXYGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie1","Serie2",0);
37. $Test->clearShadow();
38.
39. // Draw the title
40. $Title = "Drawing X versus Y charts trigonometric functions ";
41. $Test-
>drawTextBox(0,280,300,300,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);
42.
43. // Draw the legend
44. $Test->setFontProperties("Fonts/pf_arma_five.ttf",6);
45. $DataSet->RemoveSerie("Serie2");
46. $Test->drawLegend(160,5,$DataSet-
>GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE);
47.
48. $Test->Render("example24.png");
49.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;

// Compute the points


for($i=0;$i<=360;$i=$i+10)
{
$DataSet->AddPoint(cos($i*3.14/180)*80+$i,"Serie1");
$DataSet->AddPoint(sin($i*3.14/180)*80+$i,"Serie2");
}

$DataSet->SetSerieName("Trigonometric function","Serie1");
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetXAxisName("X Axis");
$DataSet->SetYAxisName("Y Axis");

// Initialise the graph


$Test = new pChart(300,300);
$Test->drawGraphAreaGradient(0,0,0,-100,TARGET_BACKGROUND);

// Prepare the graph area


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(55,30,270,230);
$Test->drawXYScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie1","Serie2",213,217,221,TRUE,45);
$Test->drawGraphArea(213,217,221,FALSE);
$Test->drawGraphAreaGradient(30,30,30,-50);
$Test->drawGrid(4,TRUE,230,230,230,20);

// Draw the chart


$Test->setShadowProperties(2,2,0,0,0,60,4);
$Test->drawXYGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie1","Serie2",0);
$Test->clearShadow();

// Draw the title


$Title = "Drawing X versus Y charts trigonometric functions ";
$Test-
>drawTextBox(0,280,300,300,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);

// Draw the legend


$Test->setFontProperties("Fonts/pf_arma_five.ttf",6);
$DataSet->RemoveSerie("Serie2");
$Test->drawLegend(160,5,$DataSet-
>GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE);

$Test->Render("example24.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #9 - Graph labels

This example shows how to add labels to a chart. Data are manualy set using the AddPoint()
method of the pData class. The graph function called is drawLineGraph() overlayed by a
drawPlotGraph(). Two labels are added using the setLabel() function. Running this script will create
a example9.png file in the current directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(0,70,70,0,0,70,70,0,0,70),"Serie1");
9. $DataSet->AddPoint(array(0.5,2,4.5,8,12.5,18,24.5,32,40.5,50),"Serie2");
10.
11. $DataSet->AddAllSeries();
12. $DataSet->SetAbsciseLabelSerie();
13. $DataSet->SetSerieName("January","Serie1");
14. $DataSet->SetSerieName("February","Serie2");
15.
16. // Initialise the graph
17. $Test = new pChart(700,230);
18. $Test->setFontProperties("Fonts/tahoma.ttf",8);
19. $Test->setGraphArea(50,30,585,200);
20. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
21. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
22. $Test->drawGraphArea(255,255,255,TRUE);
23. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
24. $Test->drawGrid(4,TRUE,230,230,230,50);
25.
26. // Draw the 0 line
27. $Test->setFontProperties("Fonts/tahoma.ttf",6);
28. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
29.
30. // Draw the line graph
31. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
32. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
33.
34. // Set labels
35. $Test->setFontProperties("Fonts/tahoma.ttf",8);
36. $Test->setLabel($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie1","2","Daily
incomes",221,230,174);
37. $Test->setLabel($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie2","6","Production break",239,233,195);
38.
39. // Finish the graph
40. $Test->setFontProperties("Fonts/tahoma.ttf",8);
41. $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
42. $Test->setFontProperties("Fonts/tahoma.ttf",10);
43. $Test->drawTitle(50,22,"Example 9",50,50,50,585);
44. $Test->Render("example9.png");
45.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(0,70,70,0,0,70,70,0,0,70),"Serie1");
$DataSet->AddPoint(array(0.5,2,4.5,8,12.5,18,24.5,32,40.5,50),"Serie2");

$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,585,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
// Set labels
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setLabel($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie1","2","Daily incomes",221,230,174);
$Test->setLabel($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie2","6","Production break",239,233,195);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 9",50,50,50,585);
$Test->Render("example9.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #10 - Small "Fast Graphs"

It can be usefull to add small graphs on web pages tracking pages views or visitors per hour. You can use
pChart to draw minimal pieces of charts. In this example Data are manualy set using the AddPoint() method of
the pData class. The graph function called is drawLineGraph(). Running this script will create a
SmallGraph.png file in the current directory.

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1");
9. $DataSet->AddAllSeries();
10.$DataSet->SetAbsciseLabelSerie();
11.$DataSet->SetSerieName("January","Serie1");
12.
13.// Initialise the graph
14.$Test = new pChart(100,30);
15.$Test->setFontProperties("Fonts/tahoma.ttf",8);
16.$Test->drawFilledRoundedRectangle(2,2,98,28,2,230,230,230);
17.$Test->setGraphArea(5,5,95,25);
18.$Test->drawGraphArea(255,255,255);
19. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
20.
21.// Draw the line graph
22.$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
23.
24.// Finish the graph
25.$Test->Render("SmallGraph.png");
26.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,-3,2,-3,3,2,1,0,7,4,-3,2,-3,3,5,1,0,7),"Serie1");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");

// Initialise the graph


$Test = new pChart(100,30);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawFilledRoundedRectangle(2,2,98,28,2,230,230,230);
$Test->setGraphArea(5,5,95,25);
$Test->drawGraphArea(255,255,255);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());

// Finish the graph


$Test->Render("SmallGraph.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #12 - Using pCache for live charting

This example shows how to use the pCache class to enhance graph rendering time. Data used to
build the graph are static in this example, this will probably be not the case in your application :
replace the pData stuff with your own. The unique ID associated to this chart is Graph1, it is
needed for the pCache library to get only cached files associated to this script.

After filling the pData structure we're invoking the GetFromCache function. If a cached copy
already exists, it is sent to the user browser and the script is interrupted meaning that all the
following lines will never be executed.

If the graph isn't in the cache, the chart is created, drawn and then pushed to the cache using the
WriteToCache function. Calling this function is mandatory for the cache to be available the next
time an user will request the same chart.
Running this script will send the picture directly to the user browser. Don't run it in from
command line!

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5. include("pChart/pCache.class");
6.
7. // Dataset definition
8. $DataSet = new pData;
9. $DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
10.$DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2");
11.$DataSet->AddAllSeries();
12.$DataSet->SetAbsciseLabelSerie();
13.$DataSet->SetSerieName("January","Serie1");
14.$DataSet->SetSerieName("February","Serie2");
15.
16.// Cache definition
17.$Cache = new pCache();
18.$Cache->GetFromCache("Graph1",$DataSet->GetData());
19.
20.// Initialise the graph
21.$Test = new pChart(700,230);
22.$Test->setFontProperties("Fonts/tahoma.ttf",8);
23.$Test->setGraphArea(50,30,585,200);
24.$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
25.$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
26.$Test->drawGraphArea(255,255,255,TRUE);
27. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
28.$Test->drawGrid(4,TRUE,230,230,230,50);
29.
30.// Draw the 0 line
31.$Test->setFontProperties("Fonts/tahoma.ttf",6);
32.$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
33.
34.// Draw the cubic curve graph
35.$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
36.
37.// Finish the graph
38.$Test->setFontProperties("Fonts/tahoma.ttf",8);
39.$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
40.$Test->setFontProperties("Fonts/tahoma.ttf",10);
41.$Test->drawTitle(50,22,"Example 1",50,50,50,585);
42.
43.// Render the graph
44.$Cache->WriteToCache("Graph1",$DataSet->GetData(),$Test);
45.$Test->Stroke();
46.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");
include("pChart/pCache.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(1,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
$DataSet->AddPoint(array(1,4,2,6,2,3,0,1,5,1,2,4,5,2,1,0,6,4,2),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");

// Cache definition
$Cache = new pCache();
$Cache->GetFromCache("Graph1",$DataSet->GetData());

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(50,30,585,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the cubic curve graph


$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 1",50,50,50,585);

// Render the graph


$Cache->WriteToCache("Graph1",$DataSet->GetData(),$Test);
$Test->Stroke();
?>

Using the cache work only for graphs that are sent to the user browser using the Stroke()
command.

Example #16 - Playing with line style, Custom X Scale, Picture inclusion

This example shows various graphing techniques playing with line graph style using the
setLineStyle fonction. The X scale is also stretched showing only one label every 3 points using the
last parameter of the drawScale function. We're also including the external picture Sample/logo.png
calling the drawFromPNG function with a default alpha transparency of 0.

This code can looks a bit tricky because using various exotic functionalities but is also more
representative of what you'll probably do to customize a bit your charts!

Output :
Source code :

view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(10,9.4,7.7,5,1.7,-1.7,-5,-7.7,-9.4,-10,-9.4,-7.7,-5,-
1.8,1.7),"Serie1");
9. $DataSet->AddPoint(array(0,3.4,6.4,8.7,9.8,9.8,8.7,6.4,3.4,0,-3.4,-6.4,-8.6,-9.8,-
9.9),"Serie2");
10. $DataSet->AddPoint(array(7.1,9.1,10,9.7,8.2,5.7,2.6,-0.9,-4.2,-7.1,-9.1,-10,-9.7,-8.2,-
5.8),"Serie3");
11. $DataSet-
>AddPoint(array("Jan","Jan","Jan","Feb","Feb","Feb","Mar","Mar","Mar","Apr","Apr","Ap
r","May","May","May"),"Serie4");
12. $DataSet->AddAllSeries();
13. $DataSet->SetAbsciseLabelSerie("Serie4");
14. $DataSet->SetSerieName("Max Average","Serie1");
15. $DataSet->SetSerieName("Min Average","Serie2");
16. $DataSet->SetSerieName("Temperature","Serie3");
17. $DataSet->SetYAxisName("Temperature");
18. $DataSet->SetXAxisName("Month of the year");
19.
20. // Initialise the graph
21. $Test = new pChart(700,230);
22. $Test->reportWarnings("GD");
23. $Test->setFixedScale(-12,12);
24. $Test->setFontProperties("Fonts/tahoma.ttf",8);
25. $Test->setGraphArea(65,30,570,185);
26. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
27. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
28. $Test->drawGraphArea(255,255,255,TRUE);
29. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE,3);
30. $Test->drawGrid(4,TRUE,230,230,230,50);
31.
32. // Draw the 0 line
33. $Test->setFontProperties("Fonts/tahoma.ttf",6);
34. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
35.
36. // Draw the area
37. $DataSet->RemoveSerie("Serie4");
38. $Test->drawArea($DataSet->GetData(),"Serie1","Serie2",239,238,227,50);
39. $DataSet->RemoveSerie("Serie3");
40. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
41.
42. // Draw the line graph
43. $Test->setLineStyle(1,6);
44. $DataSet->RemoveAllSeries();
45. $DataSet->AddSerie("Serie3");
46. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
47. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
48.
49. // Write values on Serie1 & Serie2
50. $Test->setFontProperties("Fonts/tahoma.ttf",8);
51. $Test->writeValues($DataSet->GetData(),$DataSet->GetDataDescription(),"Serie3");
52.
53. // Finish the graph
54. $Test->setFontProperties("Fonts/tahoma.ttf",8);
55. $Test->drawLegend(590,90,$DataSet->GetDataDescription(),255,255,255);
56. $Test->setFontProperties("Fonts/tahoma.ttf",10);
57. $Test->drawTitle(60,22,"example 15",50,50,50,585);
58.
59. // Add an image
60. $Test->drawFromPNG("Sample/logo.png",584,35);
61.
62. // Render the chart
63. $Test->Render("example15.png");
64.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(10,9.4,7.7,5,1.7,-1.7,-5,-7.7,-9.4,-10,-9.4,-7.7,-5,-
1.8,1.7),"Serie1");
$DataSet->AddPoint(array(0,3.4,6.4,8.7,9.8,9.8,8.7,6.4,3.4,0,-3.4,-6.4,-8.6,-
9.8,-9.9),"Serie2");
$DataSet->AddPoint(array(7.1,9.1,10,9.7,8.2,5.7,2.6,-0.9,-4.2,-7.1,-9.1,-10,-
9.7,-8.2,-5.8),"Serie3");
$DataSet-
>AddPoint(array("Jan","Jan","Jan","Feb","Feb","Feb","Mar","Mar","Mar","Apr","Apr
","Apr","May","May","May"),"Serie4");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie4");
$DataSet->SetSerieName("Max Average","Serie1");
$DataSet->SetSerieName("Min Average","Serie2");
$DataSet->SetSerieName("Temperature","Serie3");
$DataSet->SetYAxisName("Temperature");
$DataSet->SetXAxisName("Month of the year");

// Initialise the graph


$Test = new pChart(700,230);
$Test->reportWarnings("GD");
$Test->setFixedScale(-12,12);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(65,30,570,185);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE,3);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the area


$DataSet->RemoveSerie("Serie4");
$Test->drawArea($DataSet->GetData(),"Serie1","Serie2",239,238,227,50);
$DataSet->RemoveSerie("Serie3");
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());

// Draw the line graph


$Test->setLineStyle(1,6);
$DataSet->RemoveAllSeries();
$DataSet->AddSerie("Serie3");
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Write values on Serie1 & Serie2


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->writeValues($DataSet->GetData(),$DataSet-
>GetDataDescription(),"Serie3");

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(590,90,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"example 15",50,50,50,585);

// Add an image
$Test->drawFromPNG("Sample/logo.png",584,35);

// Render the chart


$Test->Render("example15.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #16 - Importing CSV data

This example shows how to import a CSV file containing headers and one data serie dedicated for
the X Axis. Data importation is made using the ImportFromCSV function. The Y axis caption is set
using the SetYAxisName function. Error reporting is turned on and messages are redirected on the
graph calling the ReportWarnings("GD") function. X labels are rotated 90° left specifying the angle
when calling the drawScale function.

Output :

Note on the dataset

Data are retrieved from a CSV file named CO2.csv. This file contains many data colums. The first
row contains headers that will be used to name series (Months). Column #1 is used as index (Years).
We are only loading row 1,2,3 and 4 from this file.
Click here to download CO2.csv

Source code :
view plaincopy to clipboardprint?
1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->ImportFromCSV("Sample/CO2.csv",",",array(1,2,3,4),TRUE,0);
9. $DataSet->AddAllSeries();
10. $DataSet->SetAbsciseLabelSerie();
11. $DataSet->SetYAxisName("CO2 concentrations");
12.
13. // Initialise the graph
14. $Test = new pChart(700,230);
15. $Test->reportWarnings("GD");
16. $Test->setFontProperties("Fonts/tahoma.ttf",8);
17. $Test->setGraphArea(60,30,680,180);
18. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
19. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
20. $Test->drawGraphArea(255,255,255,TRUE);
21. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,90,2);
22. $Test->drawGrid(4,TRUE,230,230,230,50);
23.
24. // Draw the 0 line
25. $Test->setFontProperties("Fonts/tahoma.ttf",6);
26. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
27.
28. // Draw the line graph
29. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
30. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
31.
32. // Finish the graph
33. $Test->setFontProperties("Fonts/tahoma.ttf",8);
34. $Test->drawLegend(70,40,$DataSet->GetDataDescription(),255,255,255);
35. $Test->setFontProperties("Fonts/tahoma.ttf",10);
36. $Test->drawTitle(60,22,"CO2 concentrations at Mauna Loa",50,50,50,585);
37. $Test->Render("example16.png");
38.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->ImportFromCSV("Sample/CO2.csv",",",array(1,2,3,4),TRUE,0);
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetYAxisName("CO2 concentrations");

// Initialise the graph


$Test = new pChart(700,230);
$Test->reportWarnings("GD");
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(60,30,680,180);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,90,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(70,40,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"CO2 concentrations at Mauna Loa",50,50,50,585);
$Test->Render("example16.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #19 - Error reporting

This example shows how to activate and redirect error reporting by calling the ReportWarnings
function. Specifying "GD" as output will redirect all the warning on the rendered picture (red
box).The Y axis caption is set using the SetYAxisName function. In this example error message are
generated because Serie2 has no description set. To correct this, pChart is setting the description to
the serie ID : "Serie2". To avoid this message simply add a $DataSet->SetSerieName("Serie
Name","Serie2"); call.

Output :

Source code :

view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(10,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
9. $DataSet->AddPoint(array(1,4,2,6,2,3,0,1,-5,1,2,4,5,2,1,0,6,4,30),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie();
12. $DataSet->SetXAxisName("Samples");
13. $DataSet->SetYAxisName("Temperature");
14. $DataSet->SetSerieName("January","Serie1");
15.
16. // Initialise the graph
17. $Test = new pChart(700,230);
18. $Test->reportWarnings("GD");
19. $Test->setFontProperties("Fonts/tahoma.ttf",8);
20. $Test->setGraphArea(60,30,585,185);
21. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
22. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
23. $Test->drawGraphArea(255,255,255,TRUE);
24. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
25. $Test->drawGrid(4,TRUE,230,230,230,50);
26.
27. // Draw the 0 line
28. $Test->setFontProperties("Fonts/tahoma.ttf",6);
29. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
30.
31. // Draw the cubic curve graph
32. $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
33.
34. // Finish the graph
35. $Test->setFontProperties("Fonts/tahoma.ttf",8);
36. $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
37. $Test->setFontProperties("Fonts/tahoma.ttf",10);
38. $Test->drawTitle(50,22,"Example 19",50,50,50,585);
39. $Test->Render("example19.png");
40.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(10,4,3,2,3,3,2,1,0,7,4,3,2,3,3,5,1,0,7),"Serie1");
$DataSet->AddPoint(array(1,4,2,6,2,3,0,1,-5,1,2,4,5,2,1,0,6,4,30),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetXAxisName("Samples");
$DataSet->SetYAxisName("Temperature");
$DataSet->SetSerieName("January","Serie1");

// Initialise the graph


$Test = new pChart(700,230);
$Test->reportWarnings("GD");
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(60,30,585,185);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line
$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the cubic curve graph


$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 19",50,50,50,585);
$Test->Render("example19.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #18 - Missing values

This example shows how pChart is dealing with missing values. Both line and curve graphs are
interrupted. The Y axis caption is set using the SetYAxisName function. Different graph type are
associated to different series calling both RemoveSerie and AddSerie.

Output :

Source code :

view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(2,5,7,"","",5,6,4,8,4,"",2,5,6,4,5,6,7,6),"Serie1");
9. $DataSet->AddPoint(array(-1,-3,-1,-2,-4,-1,"",-4,-5,-3,-2,-2,-3,-3,-5,-4,-3,-1,""),"Serie2");
10. $DataSet->AddAllSeries();
11. $DataSet->SetAbsciseLabelSerie();
12. $DataSet->SetSerieName("Raw #1","Serie1");
13. $DataSet->SetSerieName("Raw #2","Serie2");
14. $DataSet->SetYAxisName("Response time");
15. $DataSet->SetXAxisName("Sample #ID");
16.
17. // Initialise the graph
18. $Test = new pChart(700,230);
19. $Test->setFontProperties("Fonts/tahoma.ttf",8);
20. $Test->setGraphArea(55,30,585,185);
21. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
22. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
23. $Test->drawGraphArea(255,255,255,TRUE);
24. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);
25. $Test->drawGrid(4,TRUE,230,230,230,50);
26.
27. // Draw the 0 line
28. $Test->setFontProperties("Fonts/tahoma.ttf",6);
29. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
30.
31. // Draw the line graph
32. $DataSet->RemoveSerie("Serie2");
33. $Test->drawFilledLineGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),60,TRUE);
34.
35. // Draw the curve graph
36. $DataSet->RemoveSerie("Serie1");
37. $DataSet->AddSerie("Serie2");
38. $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
39. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
40.
41. // Finish the graph
42. $Test->setFontProperties("Fonts/tahoma.ttf",8);
43. $Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
44. $Test->setFontProperties("Fonts/tahoma.ttf",10);
45. $Test->drawTitle(50,22,"Example 18",50,50,50,585);
46. $Test->Render("example18.png");
47.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(2,5,7,"","",5,6,4,8,4,"",2,5,6,4,5,6,7,6),"Serie1");
$DataSet->AddPoint(array(-1,-3,-1,-2,-4,-1,"",-4,-5,-3,-2,-2,-3,-3,-5,-4,-3,-
1,""),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie();
$DataSet->SetSerieName("Raw #1","Serie1");
$DataSet->SetSerieName("Raw #2","Serie2");
$DataSet->SetYAxisName("Response time");
$DataSet->SetXAxisName("Sample #ID");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(55,30,585,185);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the line graph


$DataSet->RemoveSerie("Serie2");
$Test->drawFilledLineGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),60,TRUE);

// Draw the curve graph


$DataSet->RemoveSerie("Serie1");
$DataSet->AddSerie("Serie2");
$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(600,30,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(50,22,"Example 18",50,50,50,585);
$Test->Render("example18.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #19 - Playing with axis formats

This example shows how axis formats can be modified. Here data on the Y axis are representing a
number of seconds and are displayed as HH:MM:SS calling SetYAxisFormat("time"). Data on the
X Axis are dated written in the unix time stamp format and are formated as DD/MM/YYY calling
SetXAxisFormat("date").

Output :

Source code :

view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(100,320,200,10,43),"Serie1");
9. $DataSet->AddPoint(array(23,432,43,153,234),"Serie2");
10. $DataSet-
>AddPoint(array(1217541600,1217628000,1217714400,1217800800,1217887200),"Serie3"
);
11. $DataSet->AddSerie("Serie1");
12. $DataSet->AddSerie("Serie2");
13. $DataSet->SetAbsciseLabelSerie("Serie3");
14. $DataSet->SetSerieName("Incoming","Serie1");
15. $DataSet->SetSerieName("Outgoing","Serie2");
16. $DataSet->SetYAxisName("Call duration");
17. $DataSet->SetYAxisFormat("time");
18. $DataSet->SetXAxisFormat("date");
19.
20. // Initialise the graph
21. $Test = new pChart(700,230);
22. $Test->setFontProperties("Fonts/tahoma.ttf",8);
23. $Test->setGraphArea(85,30,650,200);
24. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
25. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
26. $Test->drawGraphArea(255,255,255,TRUE);
27. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
28. $Test->drawGrid(4,TRUE,230,230,230,50);
29.
30. // Draw the 0 line
31. $Test->setFontProperties("Fonts/tahoma.ttf",6);
32. $Test->drawTreshold(0,143,55,72,TRUE,TRUE);
33.
34. // Draw the line graph
35. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
36. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
37.
38. // Finish the graph
39. $Test->setFontProperties("Fonts/tahoma.ttf",8);
40. $Test->drawLegend(90,35,$DataSet->GetDataDescription(),255,255,255);
41. $Test->setFontProperties("Fonts/tahoma.ttf",10);
42. $Test->drawTitle(60,22,"example 17",50,50,50,585);
43. $Test->Render("example17.png");
44.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(100,320,200,10,43),"Serie1");
$DataSet->AddPoint(array(23,432,43,153,234),"Serie2");
$DataSet-
>AddPoint(array(1217541600,1217628000,1217714400,1217800800,1217887200),"Serie3"
);
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("Incoming","Serie1");
$DataSet->SetSerieName("Outgoing","Serie2");
$DataSet->SetYAxisName("Call duration");
$DataSet->SetYAxisFormat("time");
$DataSet->SetXAxisFormat("date");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(85,30,650,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the 0 line


$Test->setFontProperties("Fonts/tahoma.ttf",6);
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Finish the graph


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(90,35,$DataSet->GetDataDescription(),255,255,255);
$Test->setFontProperties("Fonts/tahoma.ttf",10);
$Test->drawTitle(60,22,"example 17",50,50,50,585);
$Test->Render("example17.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #21 - Playing with backgrounds

Since release 1.27b it is now possible to customize backgrounds (Whole picture or only the graph
area) by drawing gradient overlays. In this example we are filling the background calling
drawGraphAreaGradient and specifying the target to be the background (Whole picture)
TARGET_BACKGROUND. We are calling a second time this function specifying no target, by
default it will be applyed to the graph area. The title of the graph is written calling the drawTextBox
function specifying the box position to be on the bottom of the picture, the fill color, the text
alignement. We're also applying a shading to the text content and setting the transparency of the
background box to be of 30%.

Finally we're calling the AddBorder function to draw a 2px black border around the picture. This
call must be done at the end of the chart drawing because it will resize the picture.

Output :

Source code :

view plaincopy to clipboardprint?


1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet-
>AddPoint(array(9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9),"Serie1");
9. $DataSet-
>AddPoint(array(10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14),"Serie2");
10. $DataSet->AddPoint(array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),"Serie3");
11. $DataSet->AddAllSeries();
12. $DataSet->RemoveSerie("Serie3");
13. $DataSet->SetAbsciseLabelSerie("Serie3");
14. $DataSet->SetSerieName("January","Serie1");
15. $DataSet->SetSerieName("February","Serie2");
16. $DataSet->SetYAxisName("Temperature");
17. $DataSet->SetYAxisUnit("°C");
18. $DataSet->SetXAxisUnit("h");
19.
20. // Initialise the graph
21. $Test = new pChart(700,230);
22. $Test->drawGraphAreaGradient(132,153,172,50,TARGET_BACKGROUND);
23. $Test->setFontProperties("Fonts/tahoma.ttf",8);
24. $Test->setGraphArea(60,20,585,180);
25. $Test->drawGraphArea(213,217,221,FALSE);
26. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,2);
27. $Test->drawGraphAreaGradient(162,183,202,50);
28. $Test->drawGrid(4,TRUE,230,230,230,20);
29.
30. // Draw the line chart
31. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
32. $Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),2);
33.
34. // Draw the legend
35. $Test->setFontProperties("Fonts/tahoma.ttf",8);
36. $Test->drawLegend(605,142,$DataSet->GetDataDescription(),236,238,240,52,58,82);
37.
38. // Draw the title
39. $Title = "Average Temperatures during the first months of 2008 ";
40. $Test-
>drawTextBox(0,210,700,230,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);
41.
42. // Render the picture
43. $Test->AddBorder(2);
44. $Test->Render("example21.png");
45.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet-
>AddPoint(array(9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9),"Serie1");
$DataSet-
>AddPoint(array(10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14),"Serie
2");
$DataSet-
>AddPoint(array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),"Serie3");
$DataSet->AddAllSeries();
$DataSet->RemoveSerie("Serie3");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");
$DataSet->SetYAxisName("Temperature");
$DataSet->SetYAxisUnit("°C");
$DataSet->SetXAxisUnit("h");

// Initialise the graph


$Test = new pChart(700,230);
$Test->drawGraphAreaGradient(132,153,172,50,TARGET_BACKGROUND);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(60,20,585,180);
$Test->drawGraphArea(213,217,221,FALSE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,2);
$Test->drawGraphAreaGradient(162,183,202,50);
$Test->drawGrid(4,TRUE,230,230,230,20);

// Draw the line chart


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),2);

// Draw the legend


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(605,142,$DataSet-
>GetDataDescription(),236,238,240,52,58,82);

// Draw the title


$Title = "Average Temperatures during the first months of 2008 ";
$Test-
>drawTextBox(0,210,700,230,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);

// Render the picture


$Test->AddBorder(2);
$Test->Render("example21.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #23 - High quality graphics

Since release 1.27b it is now possible to customize backgrounds (Whole picture or only the graph
area) by drawing gradient overlays. In this example we are filling the background calling
drawGraphAreaGradient and specifying the target to be the background (Whole picture)
TARGET_BACKGROUND. We are calling a second time this function specifying no target, by
default it will be applyed to the graph area. The title of the graph is written calling the drawTextBox
function specifying the box position to be on the left of the picture, the fill color, the text
alignement. We're also applying a shading to the text and a 90° rotation. Transparency of the
background box is set to 30%.

Finally we're calling the addBorder function to draw a 2px black border around the picture. This
call must be done at the end of the chart drawing because it will resize the picture.

Output :

Source code :

view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet-
>AddPoint(array(9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9),"Serie1");
9. $DataSet-
>AddPoint(array(10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14),"Serie2");
10. $DataSet->AddPoint(array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),"Serie3");
11. $DataSet->AddAllSeries();
12. $DataSet->RemoveSerie("Serie3");
13. $DataSet->SetAbsciseLabelSerie("Serie3");
14. $DataSet->SetSerieName("January","Serie1");
15. $DataSet->SetSerieName("February","Serie2");
16. $DataSet->SetYAxisName("Temperature");
17. $DataSet->SetYAxisUnit("°C");
18. $DataSet->SetXAxisUnit("h");
19.
20. // Initialise the graph
21. $Test = new pChart(700,230);
22. $Test->drawGraphAreaGradient(132,173,131,50,TARGET_BACKGROUND);
23. $Test->setFontProperties("Fonts/tahoma.ttf",8);
24. $Test->setGraphArea(120,20,675,190);
25. $Test->drawGraphArea(213,217,221,FALSE);
26. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_ADDALL,213,217,221,TRUE,0,2,TRUE);
27. $Test->drawGraphAreaGradient(163,203,167,50);
28. $Test->drawGrid(4,TRUE,230,230,230,20);
29.
30. // Draw the bar chart
31. $Test->drawStackedBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),70);
32.
33. // Draw the title
34. $Title = " Average Temperatures during\r\n the first months of 2008 ";
35. $Test-
>drawTextBox(0,0,50,230,$Title,90,255,255,255,ALIGN_BOTTOM_CENTER,TRUE,0,0,
0,30);
36.
37. // Draw the legend
38. $Test->setFontProperties("Fonts/tahoma.ttf",8);
39. $Test->drawLegend(610,10,$DataSet->GetDataDescription(),236,238,240,52,58,82);
40.
41. // Render the picture
42. $Test->addBorder(2);
43. $Test->Render("example23.png");
44.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet-
>AddPoint(array(9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9),"Serie1");
$DataSet-
>AddPoint(array(10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14),"Serie
2");
$DataSet-
>AddPoint(array(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),"Serie3");
$DataSet->AddAllSeries();
$DataSet->RemoveSerie("Serie3");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("January","Serie1");
$DataSet->SetSerieName("February","Serie2");
$DataSet->SetYAxisName("Temperature");
$DataSet->SetYAxisUnit("°C");
$DataSet->SetXAxisUnit("h");

// Initialise the graph


$Test = new pChart(700,230);
$Test->drawGraphAreaGradient(132,173,131,50,TARGET_BACKGROUND);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(120,20,675,190);
$Test->drawGraphArea(213,217,221,FALSE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_ADDALL,213,217,221,TRUE,0,2,TRUE);
$Test->drawGraphAreaGradient(163,203,167,50);
$Test->drawGrid(4,TRUE,230,230,230,20);

// Draw the bar chart


$Test->drawStackedBarGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),70);

// Draw the title


$Title = " Average Temperatures during\r\n the first months of 2008 ";
$Test-
>drawTextBox(0,0,50,230,$Title,90,255,255,255,ALIGN_BOTTOM_CENTER,TRUE,0,0,0,30)
;

// Draw the legend


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(610,10,$DataSet->GetDataDescription(),236,238,240,52,58,82);

// Render the picture


$Test->addBorder(2);
$Test->Render("example23.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

Example #23 - Customizing plot charts

Since release 1.27b it is possible to associate a picture (only GIF files are supported) to one data
serie. This picture will replace the bubles while drawing a plot chart. First associate one picture to
one serie calling the SetSerieSymbol function of the pData class. The title of the chart is written
over the grap area using the drawTextBox function setting a transparency factor of 30%

Running this script will create a example22.png file in the current directory.

Output :
Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(60,70,90,110,100,90),"Serie1");
9. $DataSet->AddPoint(array(40,50,60,80,70,60),"Serie2");
10. $DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May","Jun"),"Serie3");
11. $DataSet->AddSerie("Serie1");
12. $DataSet->AddSerie("Serie2");
13. $DataSet->SetAbsciseLabelSerie("Serie3");
14. $DataSet->SetSerieName("Company A","Serie1");
15. $DataSet->SetSerieName("Company B","Serie2");
16. $DataSet->SetYAxisName("Product sales");
17. $DataSet->SetYAxisUnit("k");
18. $DataSet->SetSerieSymbol("Serie1","Sample/Point_Asterisk.gif");
19. $DataSet->SetSerieSymbol("Serie2","Sample/Point_Cd.gif");
20.
21. // Initialise the graph
22. $Test = new pChart(700,230);
23. $Test->setFontProperties("Fonts/tahoma.ttf",8);
24. $Test->setGraphArea(65,30,650,200);
25. $Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
26. $Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
27. $Test->drawGraphArea(255,255,255,TRUE);
28. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);
29. $Test->drawGrid(4,TRUE,230,230,230,50);
30.
31. // Draw the title
32. $Test->setFontProperties("Fonts/pf_arma_five.ttf",6);
33. $Title = "Comparative product sales for company A & B ";
34. $Test->drawTextBox(65,30,650,45,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);
35.
36. // Draw the line graph
37. $Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
38. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
39.
40. // Draw the legend
41. $Test->setFontProperties("Fonts/tahoma.ttf",8);
42. $Test->drawLegend(80,60,$DataSet->GetDataDescription(),255,255,255);
43.
44. // Render the chart
45. $Test->Render("example22.png");
46.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(60,70,90,110,100,90),"Serie1");
$DataSet->AddPoint(array(40,50,60,80,70,60),"Serie2");
$DataSet->AddPoint(array("Jan","Feb","Mar","Apr","May","Jun"),"Serie3");
$DataSet->AddSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("Company A","Serie1");
$DataSet->SetSerieName("Company B","Serie2");
$DataSet->SetYAxisName("Product sales");
$DataSet->SetYAxisUnit("k");
$DataSet->SetSerieSymbol("Serie1","Sample/Point_Asterisk.gif");
$DataSet->SetSerieSymbol("Serie2","Sample/Point_Cd.gif");

// Initialise the graph


$Test = new pChart(700,230);
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->setGraphArea(65,30,650,200);
$Test->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
$Test->drawRoundedRectangle(5,5,695,225,5,230,230,230);
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2,TRUE);
$Test->drawGrid(4,TRUE,230,230,230,50);

// Draw the title


$Test->setFontProperties("Fonts/pf_arma_five.ttf",6);
$Title = "Comparative product sales for company A & B ";
$Test-
>drawTextBox(65,30,650,45,$Title,0,255,255,255,ALIGN_RIGHT,TRUE,0,0,0,30);

// Draw the line graph


$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Draw the legend


$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->drawLegend(80,60,$DataSet->GetDataDescription(),255,255,255);

// Render the chart


$Test->Render("example22.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().
Example #26 - Playing with shadows and second Y axis

Since release 1.27d it is possible to draw shadows behind drawn pixels. Shadow can be added to
any plot-drawn objects line lines and cubics. Use shadows with caution as this will add extra
computing time to your charts. If you want to display rendered data on your web pages, I invite you
to use the pCache class to speed up the processing time.

This example is showing how to display two data series with dedicated Y axis. Basic way to
associate a data serie to one axis is to first add only the attached data series to the grapher using the
AddSerie() function of the pData class and then invoke the drawScale() function of the pChart class.
Before drawing the right scale, use the clearScale() function and remove the previously graphed
series with the RemoveSerie() function of the pData class. Then add the remaining series using the
AddSerie() function and compute the second Y axis calling the drawRightScale() function.

Shadows are activated calling the setShadowProperties() function. You must remove the shadow
engine calling the clearShadow() when you've finished to draw your data series. If you forget to
remove the shadow, you'll experience strange graphing effects.

Running this script will create a example26.png file in the current directory.

Output :

Source code :
view plaincopy to clipboardprint?

1. <?php
2. // Standard inclusions
3. include("pChart/pData.class");
4. include("pChart/pChart.class");
5.
6. // Dataset definition
7. $DataSet = new pData;
8. $DataSet->AddPoint(array(110,101,118,108,110,106,104),"Serie1");
9. $DataSet->AddPoint(array(700,2705,2041,1712,2051,846,903),"Serie2");
10. $DataSet->AddPoint(array("03 Oct","02 Oct","01 Oct","30 Sep","29 Sep","28 Sep","27 Se
p"),"Serie3");
11. $DataSet->AddSerie("Serie1");
12. $DataSet->SetAbsciseLabelSerie("Serie3");
13. $DataSet->SetSerieName("SourceForge Rank","Serie1");
14. $DataSet->SetSerieName("Web Hits","Serie2");
15.
16. // Initialise the graph
17. $Test = new pChart(660,230);
18. $Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND);
19.
20. // Prepare the graph area
21. $Test->setFontProperties("fonts/tahoma.ttf",8);
22. $Test->setGraphArea(60,40,595,190);
23.
24. // Initialise graph area
25. $Test->setFontProperties("fonts/tahoma.ttf",8);
26.
27. // Draw the SourceForge Rank graph
28. $DataSet->SetYAxisName("Sourceforge Rank");
29. $Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0);
30. $Test->drawGraphAreaGradient(40,40,40,-50);
31. $Test->drawGrid(4,TRUE,230,230,230,10);
32. $Test->setShadowProperties(3,3,0,0,0,30,4);
33. $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
34. $Test->clearShadow();
35. $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet-
>GetDataDescription(),.1,30);
36. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
37.
38. // Clear the scale
39. $Test->clearScale();
40.
41. // Draw the 2nd graph
42. $DataSet->RemoveSerie("Serie1");
43. $DataSet->AddSerie("Serie2");
44. $DataSet->SetYAxisName("Web Hits");
45. $Test->drawRightScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0);
46. $Test->drawGrid(4,TRUE,230,230,230,10);
47. $Test->setShadowProperties(3,3,0,0,0,30,4);
48. $Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
49. $Test->clearShadow();
50. $Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet-
>GetDataDescription(),.1,30);
51. $Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);
52.
53. // Write the legend (box less)
54. $Test->setFontProperties("fonts/tahoma.ttf",8);
55. $Test->drawLegend(530,5,$DataSet-
>GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE);
56.
57. // Write the title
58. $Test->setFontProperties("fonts/MankSans.ttf",18);
59. $Test->setShadowProperties(1,1,0,0,0);
60. $Test->drawTitle(0,0,"SourceForge ranking summary",255,255,255,660,30,TRUE);
61. $Test->clearShadow();
62.
63. // Render the picture
64. $Test->Render("example26.png");
65.?>
<?php
// Standard inclusions
include("pChart/pData.class");
include("pChart/pChart.class");

// Dataset definition
$DataSet = new pData;
$DataSet->AddPoint(array(110,101,118,108,110,106,104),"Serie1");
$DataSet->AddPoint(array(700,2705,2041,1712,2051,846,903),"Serie2");
$DataSet->AddPoint(array("03 Oct","02 Oct","01 Oct","30 Sep","29 Sep","28
Sep","27 Sep"),"Serie3");
$DataSet->AddSerie("Serie1");
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("SourceForge Rank","Serie1");
$DataSet->SetSerieName("Web Hits","Serie2");

// Initialise the graph


$Test = new pChart(660,230);
$Test->drawGraphAreaGradient(90,90,90,90,TARGET_BACKGROUND);

// Prepare the graph area


$Test->setFontProperties("fonts/tahoma.ttf",8);
$Test->setGraphArea(60,40,595,190);

// Initialise graph area


$Test->setFontProperties("fonts/tahoma.ttf",8);

// Draw the SourceForge Rank graph


$DataSet->SetYAxisName("Sourceforge Rank");
$Test->drawScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0);
$Test->drawGraphAreaGradient(40,40,40,-50);
$Test->drawGrid(4,TRUE,230,230,230,10);
$Test->setShadowProperties(3,3,0,0,0,30,4);
$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->clearShadow();
$Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet-
>GetDataDescription(),.1,30);
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Clear the scale


$Test->clearScale();

// Draw the 2nd graph


$DataSet->RemoveSerie("Serie1");
$DataSet->AddSerie("Serie2");
$DataSet->SetYAxisName("Web Hits");
$Test->drawRightScale($DataSet->GetData(),$DataSet-
>GetDataDescription(),SCALE_NORMAL,213,217,221,TRUE,0,0);
$Test->drawGrid(4,TRUE,230,230,230,10);
$Test->setShadowProperties(3,3,0,0,0,30,4);
$Test->drawCubicCurve($DataSet->GetData(),$DataSet->GetDataDescription());
$Test->clearShadow();
$Test->drawFilledCubicCurve($DataSet->GetData(),$DataSet-
>GetDataDescription(),.1,30);
$Test->drawPlotGraph($DataSet->GetData(),$DataSet-
>GetDataDescription(),3,2,255,255,255);

// Write the legend (box less)


$Test->setFontProperties("fonts/tahoma.ttf",8);
$Test->drawLegend(530,5,$DataSet-
>GetDataDescription(),0,0,0,0,0,0,255,255,255,FALSE);

// Write the title


$Test->setFontProperties("fonts/MankSans.ttf",18);
$Test->setShadowProperties(1,1,0,0,0);
$Test->drawTitle(0,0,"SourceForge ranking summary",255,255,255,660,30,TRUE);
$Test->clearShadow();

// Render the picture


$Test->Render("example26.png");
?>

If you want to send the picture directly in a browser, replace the Render() command by
Stroke().

You might also like