還有疑問的朋友可以加我QQ:460634320,大家一起討論。
效果圖:
複製程式碼 程式碼如下:
$dataname = array();
$datavalue = array( );//data裡面的值
$i = 0;
$j = 0;
$k = 0;
$num = sizeof($data);
foreach($ data as $key => $val){
$dataname[] = $key;
$datavalue[] = $val;
}
$width = $num * ($twidth + $ tspace) + 20 ;//取得影像的寬度
$im = imagecreate($width,$height);//建立圖片
$bgcolor = imagecolorallocate($im,255,255,255);//背景色
$jcolor = imagecolorallocate($im,255,255,0);//矩形的背景色
$acolor = imagecolorallocate($im,0,0,0);//線的顏色
imageline($im ,25,$height-20,$width-5,$height -20,$acolor);//X軸
imageline($im,25,$height-20,25,2,$acolor);/ /Y軸
while($iimagefilledrectangle($im,$i*($tspace+$twidth)+40,$height-$datavalue[$i]-20,$i* ($twidth+$tspace)+$tspace+40,$height-20,$jcolor);//畫矩形
imagestring($im,3,$i*($tspace+$twidth)+40+$twidth/ 2,$height-$datavalue[$i]-35,$datavalue[$i],$acolor);//在柱子上面寫出值
imagestring($im,3,$i*($tspace+$ twidth)+40+$twidth/2,$height-15,$dataname[$i],$acolor);//在柱子下方寫出數值
$i ++;
}
while ($j imageline($im,25,($height-20)-$j*8,28,($height-20)-$j*8,$acolor);/ /畫出刻度
imagestring($im,2,5,($height-30)-$j*8,$j*10,$acolor);//標出刻度值
$j = $ j +10;
}
imagejpeg($im);
}
$data =array("1"=>25,"2"=>30,"3" =>21 ) ;
createImage($data,40,40,300);
?>