ホームページ  >  記事  >  バックエンド開発  >  縦棒グラフを描画するための PHP 関数コード_PHP チュートリアル

縦棒グラフを描画するための PHP 関数コード_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-20 11:00:42846ブラウズ

PHPで縦棒グラフを描画するための関数コードを見てみましょう あまりにも言い過ぎなので見てみましょう。 ​

PHPで縦棒グラフを描くための関数コードを見てみましょう あまりにも言い過ぎなので見てみましょう。

縦棒グラフを作成するためのPHP関数

キーワード: PHP

#便宜上、縦棒グラフを作成する関数をもう一つ作りました
/*パラメータの説明:
$graphdata: パーセンテージ データ (y 軸)
$label:x 軸のタイトル
$data: 実際のデータ (y 軸)
$graphwidth:画像の幅
$graphheight:画像の高さ
$graphscale: 高さ係数 ($graphheight/100 の場合)
$graphfont: フォント サイズ
$bg;背景色の値
$text: テキストの色の値
$grid: エッジの色の値
$bar:バーの色の値
$bz: 備考 (中国語はサポートされていません)
*/
関数 timage(
$グラフデータ、$ラベル、$データ、
$graphwidth,$graphheight,$graphscale,$graphfont,
$bg,$text,$grid,$bar,$bz)
{

header("Content-type:image/gif");
$image=imagecreate($graphwidth+50,$graphheight+50);
$bgcolor= imagecolorallocate ($image,$bg[0],$bg[1],$bg[2]);
$textcolor= imagecolorallocate ($image,$text[0],$text[1],$text[2]);
$gridcolor=imagecolorallocate ($image,$grid[0],$grid[1],$grid[2]);
$barcolor=imagecolorallocate ($image ,$bar[0],$bar[1],$bar[2]);
$gridabelwidth=imagefontwidth($graphfont)*3+1;
$gridableheight= imagefontheight ($graphfont);
imageline($image,$gridlabelwidth,0,$gridlabelwidth,$graphheight-1,$gridcolor);
imageline($image,0,$graphheight-1,$graphwidth-1,$graphheight-1,$gridcolor);
for($i=0;$i {
imagedashedline ($image,0,$i,$graphwidth-1,$i,$gridcolor);
imagestring($image,$graphfont,0,$i,round(($graphheight-$i)/$graphscale),$textcolor);
}

$barwidth=(($graphwidth-$gridlabelwidth)/count($graphdata))-30;#¿ ØÖÆÖùµÄ×Ü¿はい
for($i=0;$i {
$bartopx=$gridlabelwidth+(($i+1)*20)+($i*$barwidth);#¿ ØÖÆÖù¿ ¿ ×óµÄ¾àÀë
$barbottomx=$bartopx+$barwidth;
$barbottomy=$graphheight-1;#¿ ØÖÆÖùμÄϱ߽ç
$bartopy=$barbottomy-($graphdata[$i]*$graphscale);
imagefilledrectangle($image,$bartopx,$bartopy,$barbottomx,$barbottomy,$barcolor);
$labelx1=$bartopx;
$labely1=$bartopy-15;
$labelx2=$bartopx;
$labely2=$graphheight;
imagestring($image,$graphfont,$labelx1,$labely1,"$graphdata[$i]"."%",$textcolor);
imagestring($image,$graphfont,$labelx2,$labely2,"$label[$i]",$textcolor);
imagestringup ($image,$graphfont,$labelx1+10,$labely1-$gridableheight,"$data[$i]",$textcolor);
}
画像文字列($image,$graphfont,1,$graphheight+30,$bz,$textcolor);
imagegif ($image);

}
?>


www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/445490.html技術記事 PHPで縦棒グラフを描画するための関数コードを見てみましょう あまりにも言い過ぎなので見てみましょう。 PHPで縦棒グラフを描画する機能を見てみましょう...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。