📄 barchart.php
字号:
<head>
</head>
<body>
<?php
/*$arr[0] = 15;$arr[1] = 120;$arr[2] = 131;$title[0] = "Line 1";$title[1] = "Line 2";$title[2] = "Line 3";*/ $xcanvas=350; $ycanvas=350; $chartwidth=200;// $datacount=3; $pic=ImageCreate($xcanvas,$ycanvas);
$bgcolor=ImageColorAllocate($pic,200,200,200);
$color[]=ImageColorAllocate($pic,0,0,255);
$color[]=ImageColorAllocate($pic,0,150,0);
$color[]=ImageColorAllocate($pic,235,235,0);
$color[]=ImageColorAllocate($pic,255,0,0);
$max_array_value = 0;for($i=0;$i<$datacount;$i++){ if($arr[$i] > $max_array_value) { $max_array_value = $arr[$i]; }}if($max_array_value==0){die("max stat value is 0 !");}$resize_ratio= $chartwidth/$max_array_value;$barwidth =round( 200/$datacount) ;for($i=0;$i<$datacount;$i++){ if (!($j<3)) { $j=0; } else { $j++; } $startx = 50+($i*$barwidth); $endx = 50 +( $i * $barwidth) + $barwidth; $starty = 250-$arr[$i]*$resize_ratio; $endy = 250; ImageFilledRectangle($pic,$startx,$starty,$endx,$endy,$color[$j]);
Imagestring($pic,5,$startx,$starty-20,$arr[$i],$color[$j]); Imagestringup($pic,5,$endx-$barwidth,$endy+70,$title[$i],$color[$j]); } ImageLine($pic,50,50,50,250,$color[3]); ImageLine($pic,50,250,250,250,$color[3]); ImagePNG($pic,"pic.png");
ImageDestroy($pic);
?>
<img src="pic.png" border=0>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -