外枠の設定

広告

グラフの外枠の表示非表示の設定を行います。設定にはGraphクラスで用意されている「SetFrame」メソッドを使います。

Set a frame around the entire image

Parameter:
  $aDrawImgFrame  True=Draw a frame around the entire image(Default true)
  $aImgFrameColor  Frame color(Default array(0,0,0))
  $aImgFrameWeight  Width of frame(Default 1)

1番目の引数で外枠を表示するかどうかを指定します。「true」ならば外枠を表示し「false」ならば外枠を表示しません。

2番目の引数で外枠の色を指定します。色の指定方法はキーワードでの指定やRGB形式、16進数を使った指定方法などがあります。詳しくは『JpGraphにおける色の指定方法』を参照して下さい。

例えばRGB形式を使う時は「array(r, g, b)」で各値に0から255の値を指定してください(例「array(128,128,32)」)。デフォルトは「array(0,0,0)」で黒となります。

3番目の引数で外枠の線の太さを指定します。デフォルトは1です。

例えば次のように指定します。

include ("jpgraph/jpgraph.php");

$graph = new Graph(250,200);
$graph->SetFrame(true, arry(0,0,0), 2);

$graph->Stroke();

サンプル

それでは実際に試してみます。まず外枠を表示しないようにしてみます。

sample4-1.php

<?php

include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_bar.php");

$data1y = array(-8, 8, 9, 3, 5, 6);
$data2y = array(18, 2, 1, 7, 5, 4);

$graph = new Graph(250, 200, "auto"); 
$graph->SetFrame(false);
$graph->SetScale("textlin");

$graph->img->SetMargin(40, 30, 20, 40);

$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b1plot->value->Show();
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$b2plot->value->Show();

$gbplot = new AccBarPlot(array($b1plot, $b2plot));

$graph->Add($gbplot);

$graph->Stroke();
?>

上記のPHPファイルをブラウザで開いてみます。ブラウザには次のように表示されます。

外枠の設定

次に外枠を色を赤色で線の太さを3ピクセルで表示してみます。

sample4-2.php

<?php

include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_bar.php");

$data1y = array(-8, 8, 9, 3, 5, 6);
$data2y = array(18, 2, 1, 7, 5, 4);

$graph = new Graph(250,200,"auto"); 
$graph->SetFrame(true, array(255, 0, 0), 3);
$graph->SetScale("textlin");

$graph->img->SetMargin(40, 30, 20, 40);

$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b1plot->value->Show();
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
$b2plot->value->Show();

$gbplot = new AccBarPlot(array($b1plot, $b2plot));

$graph->Add($gbplot);

$graph->Stroke();
?>

上記のPHPファイルをブラウザで開いてみます。ブラウザには次のように表示されます。

外枠の設定

( Written by Tatsuo Ikura )