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 :
<?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(). |
|
|
Last updated on 08/29/2008 |