円グラフ
Example 10
円グラフ古典的なライン、曲線やプロットグラフとはわずかに異なります。
最初にデータセットは1つの系列を受け入れることができます(この例のSerie1)。
また、他のデータセットで、ラベルの各ポイント(この例のSerie2)に関連付けを指定することができます。
pDataクラスのAddPoint()を利用してデータセットを手動で設定しています。
それから、SetAbsciseLabelSerie()を利用して横座標データセットとして、Serie2を関連させています。
我々は、グラフを描くために、drawPieGraph()とdrawPieLegend()を呼んでいます。
このスクリプトを実行するとカレントディレクトリにExample10.phpファイルを作成します。
(訳注)この画像はサンプルコードのExample10.phpを出力したものです。
Example10.php ソースコード
<?php
/*
Example10 : A 3D exploded pie graph
*/
// 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("January","February","March","April","May"),"Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbsciseLabelSerie("Serie2");
// Initialise the graph
$Test = new pChart(420,250);
$Test->drawFilledRoundedRectangle(7,7,413,243,5,240,240,240);
$Test->drawRoundedRectangle(5,5,415,245,5,230,230,230);
$Test->createColorGradientPalette(195,204,56,223,110,41,5);
// Draw the pie chart
$Test->setFontProperties("Fonts/tahoma.ttf",8);
$Test->AntialiasQuality = 0;
$Test->drawPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),180,130,110,PIE_PERCENTAGE_LABEL,FALSE,50,20,5);
$Test->drawPieLegend(330,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);
// Write the title
$Test->setFontProperties("Fonts/MankSans.ttf",10);
$Test->drawTitle(10,20,"Sales per month",100,100,100);
$Test->Render("example10.png");
?>