亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

PHP 柱形統(tǒng)計(jì)圖的實(shí)現(xiàn)代碼

時(shí)間:2020-11-18 10:11:22 PHP 我要投稿

PHP 柱形統(tǒng)計(jì)圖的實(shí)現(xiàn)代碼

  效果圖:

  復(fù)制代碼 代碼如下:

  <?php

  function createImage($data,$twidth,$tspace,$height){

  header("Content-Type:image/jpeg");

  $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);//創(chuàng)建圖像

  $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($i< $num){

  imagefilledrectangle($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 < 400/10){

  imageline($im,25,($height-20)-$j*8,28,($height-20)-$j*8,$acolor);//畫出刻度

  imagestring($im,2,5,($height-30)-$j*8,$j*10,$acolor);//標(biāo)出刻度值

  $j = $j +10;

  }

  imagejpeg($im);

  }

  $data =array("1"=>25,"2"=>30,"3" =>21 );

  createImage($data,40,40,300);

  ?>