Home > Backend Development > PHP Tutorial > php绘图,请圣人修改。

php绘图,请圣人修改。

WBOY
Release: 2016-06-13 12:36:20
Original
970 people have browsed it

php绘图,请高人修改。。

<?<br />
$kuan=30;//色柱宽<br />
$jiange=20;//色柱间间隔<br />
$zuo=20;//左侧留空<br />
$you=20;//右侧留空<br />
$shang=20;//上留空<br />
$xia=10;//下留空<br />
$zuidashujuzhi=1;//初始化纵轴最大数据值<br />
if ($_GET["a"]=="") die("error id:0");<br />
$shuju=split(",",$_GET["a"]);<br />
//得到最大值<br />
for($i=0;$i<count($shuju);$i++){<br />
if(!is_numeric($shuju[$i])) die("error id:1");<br />
if($shuju[$i]>$zuidashujuzhi) $zuidashujuzhi=$shuju[$i];<br />
}<br />
//计算图像宽度 <br />
$img_kuan=$zuo+$you+$jiange+count($shuju)*($kuan+$jiange);<br />
//图像高 <br />
$img_gao=170;<br />
//存储色柱高度的数组<br />
$zhugaodu = array();<br />
$image = imagecreate($img_kuan,$img_gao);<br />
$white = imagecolorallocate($image, 0xEE, 0xEE, 0xEE);<br />
//色柱颜色<br />
$shuju_yanse =array(<br />
imagecolorallocate($image, 0x97, 0xbd, 0x00),<br />
imagecolorallocate($image, 0x00, 0x99, 0x00),<br />
imagecolorallocate($image, 0xcc, 0x33, 0x00),<br />
imagecolorallocate($image, 0xff, 0xcc, 0x00),<br />
imagecolorallocate($image, 0x33, 0x66, 0xcc),<br />
imagecolorallocate($image, 0x33, 0xcc, 0x33),<br />
imagecolorallocate($image, 0xff, 0x99, 0x33),<br />
imagecolorallocate($image, 0xcc, 0xcc, 0x99),<br />
imagecolorallocate($image, 0x99, 0xcc, 0x66),<br />
imagecolorallocate($image, 0x66, 0xff, 0x99)<br />
);<br />
<br />
<br />
<br />
//坐标轴颜色<br />
$zuobiao_yanse = imagecolorallocate($image, 0x00, 0x00, 0x00);<br />
//横轴<br />
imageline ( $image, $zuo, $img_gao-$xia, $img_kuan-$you/2, $img_gao-$xia, $zuobiao_yanse);<br />
//纵轴<br />
imageline ( $image, $zuo, $shang/2, $zuo, $img_gao-$xia, $zuobiao_yanse);<br />
<br />
<br />
<br />
//纵轴刻度,纵轴上共标注4个点,所以这里分别计算即可<br />
imageline ( $image, $zuo, $shang, $zuo+6, $shang, $zuobiao_yanse);<br />
imagestring ( $image, 3, $zuo/4, $shang,round($zuidashujuzhi), $zuobiao_yanse);<br />
imageline ( $image, $zuo, $shang+($img_gao-$shang-$xia)*1/4, $zuo+6, round($shang+($img_gao-$shang-$xia)*1/4), $zuobiao_yanse);<br />
imagestring ( $image, 3, $zuo/4, $shang+($img_gao-$shang-$xia)*1/4,round($zuidashujuzhi*3/4), $zuobiao_yanse);<br />
imageline ( $image, $zuo, $shang+($img_gao-$shang-$xia)*2/4, $zuo+6, $shang+($img_gao-$shang-$xia)*2/4, $zuobiao_yanse);<br />
imagestring ( $image, 3, $zuo/4, $shang+($img_gao-$shang-$xia)*2/4,round($zuidashujuzhi*2/4), $zuobiao_yanse);<br />
imageline ( $image, $zuo, $shang+($img_gao-$shang-$xia)*3/4, $zuo+6, $shang+($img_gao-$shang-$xia)*3/4, $zuobiao_yanse);<br />
imagestring ( $image, 3, $zuo/4, $shang+($img_gao-$shang-$xia)*3/4,round($zuidashujuzhi*1/4), $zuobiao_yanse);<br />
<br />
<br />
<br />
//得到每个柱的高度<br />
for($i=0;$i<count($shuju);$i++){<br />
array_push ($zhugaodu, round(($img_gao-$shang-$xia)*$shuju[$i]/$zuidashujuzhi));<br />
}<br />
//画数据柱<br />
$shuju_yanse_int=0;<br />
for($i=0;$i<count($shuju);$i++){<br />
imagefilledrectangle( $image,$zuo+$jiange+$i*($kuan+$jiange),$shang+($img_gao-$shang-$xia)-$zhugaodu[$i],$zuo+$jiange+$i*($kuan+$jiange)+$kuan,($img_gao-$xia)-1 ,$shuju_yanse[$shuju_yanse_int]);<br />
//因为只定义了10种颜色,所以这里做一个循环  <br />
if($shuju_yanse_int==9){<br />
$shuju_yanse_int=0;<br />
}else{<br />
$shuju_yanse_int++;<br />
}<br />
}<br />
//标注数据柱上方数据值<br />
for($i=0;$i<count($shuju);$i++){<br />
imagestring ( $image, 1, $zuo+$jiange+$i*($kuan+$jiange)+2,$shang+($img_gao-$shang-$xia)-$zhugaodu[$i]-10,$shuju[$i], $zuobiao_yanse);<br />
}<br />
header('Content-type: image/png');<br />
imagepng($image);<br />
imagedestroy($image);<br />
?>
Copy after login


这样子可以生成

img.php?a=5.4,2,30.2,4,0,6,7.7,3.8,2,3,4
用下面这个参数可以得到上面的图片。。
我现在想获取到比如5.4里面,我又分成三个属性,并且显示每个立柱的名字,请问该如何改进代码。


并且下面的类型个数不限制,比如有钢管,铝管,铜管,金管,。。。。。有若干个。
但是属性只有三个。。。。每个都为整数。。。

求高人给帮忙修改一下代码,或者给我一个简便的代码。。感谢了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template