- Home ›
- JpGraphを使ったグラフの描画 ›
- 円グラフ(PiePlot) ›
- HERE
円グラフの位置を指定する
広告
円グラフの位置を指定します。指定するにはPiePlotクラスで用意されている「SetCenter」メソッドを使います。
SetCenter function SetCenter($x,$y)
Set the center point for the PiePlot Parameter: $x X-position as fraction of width $y Y-position as fraction of height(Default 0.5)
円の中心の位置を指定します。横方向及び縦方向の位置を幅及び高さとの比率で指定します。0.5であれば丁度中央の位置ということになります。
実際には次のように記述します。
include ("jpgraph/jpgraph.php"); include ("jpgraph/jpgraph_pie.php"); $data = array(45, 23, 18, 32); $pieplot = new PiePlot($data); $pieplot->SetCenter(0.5, 0.5); $graph = new PieGraph(250, 200); $graph->Add($pieplot);
サンプル
それでは実際に試して見ます。
<?php include ("jpgraph/jpgraph.php"); include ("jpgraph/jpgraph_pie.php"); $graph = new PieGraph(250, 200, "auto"); $graph->SetFrame(true); $data = array(45, 23, 18, 32); $pieplot = new PiePlot($data); $pieplot->SetSize(0.25); $pieplot->SetCenter(0.25, 0.5); $graph->Add($pieplot); $graph->Stroke(); ?>
上記のPHPファイルをブラウザで開いてみます。ブラウザには次のように表示されます。
( Written by Tatsuo Ikura )