首頁  >  文章  >  後端開發  >  如何用php作線形圖的函數

如何用php作線形圖的函數

高洛峰
高洛峰原創
2016-12-02 11:20:531030瀏覽

很高興大家對php(做為現在的主流開發語言)如此的情有獨鍾!
下面就跟大家介紹php(做為現在的主流開發語言)作線形圖的函數: 

/* 
函數說明 
$data:y軸資料(陣列) 
$graphdata:y軸資料--百分比(陣列) 
$label:x軸資料(陣列) 
$height:影像高度 
$width:影像寬度 
$font:字號 
$dot:決定點的尺寸$text :文字色 
$dotcolor:點色 
$file:輸出影像檔案名稱 
*/ 

function qximage($data , 
$graphdata, 
,$label , .
$dot, 
$bg, 
$line, 
$text, 
$dotcolor, 
$file) 

$jc=$height/100; 

$jc=$height/100; 

$jc=$height/100; ($font); 

$image= imagecreate ($width,$height+20); 
$bg= imagecolorallocate($image ,$bg[0],$bg[1],$bg[2]); $line=imagecolorallocate($image ,$line[0],$line[1],$line[2]); 
$text=imagecolorallocate($image ,$text[0],$text[1],$text [2]); 
$dotcolor=imagecolorallocate($image ,$dotcolor[0],$dotcolor[1],$$dotcolor[2]); 
imageline ($image,0,0,0,$height,$ line); 
imageline($image,0,$height,$width,$height,$line); 
for ($i=1;$i{ 
imagedashedline($image,0, $height - $jc*$i*10 ,$width ,$height -$jc*$i*10 ,$line ); 
imagestring ($image,$font,0,$height-$jc*$i*10 ,$i*10,$text); 

for ($i=0;$i { 
#echo $tmp." 
"; 
$x1=(($width-50)/count($data) )*($i)+40; 
#echo $x1 ." 
"; 
$y1=$height-$graphdata[$i]*$jc; 
$x2=$x1; 
$y2=$y1+$ graphdata[$i]*$jc; 
#echo $y1." 
"; 
imagestring($image,$font,$x1,$y1-2*$fontheight,$graphdata[$i]."%(" .$data[$i].")",$text); 
imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor); 
imagefilltoborder ($image,$x1,$ y1,$dotcolor,$dotcolor); 
imagestring ($image,$font,$x1,$y2,$label[$i],$text); 
if ($i>0) 

imageline($image ,$tmpx1,$tmpy1,$x1,$y1,$line); 

$tmpx1=$x1;$tmpy1=$y1; 

}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn