PHP 히스토그램 생성 코드(imagefilled직사각형 함수 예시)

WBOY
풀어 주다: 2016-07-25 08:55:30
원래의
1080명이 탐색했습니다.
  1. /**

  2. * php 柱状图 imagefilledrectugle函数用例
  3. * by bbs.it-home.org
  4. */
  5. function createImage($data,$twidth,$tspace,$height){
  6. header("Content-Type:image/jpeg");
  7. $dataname = array();
  8. $datavalue = array();//data里面的值
  9. $i = 0;
  10. $j = 0;
  11. $k = 0;
  12. $num = sizeof($data);

  13. foreach($data as $key => $val){

  14. $dataname[] = $key;
  15. $datavalue[] = $val;
  16. }

  17. $width = $num * ($twidth $tspace) 20 ;//获取图像的宽度

  18. $im = imagecreate($width,$height);//创建图像

  19. $bgcolor = imagecolorallocate($im,255,255,255);//背景色

  20. $jcolor = imagecolorallocate($im,255,255,0);//矩形的背景色
  21. $acolor = imagecolorallocate($im,0,0,0);//线的颜色

  22. imageline($im,25,$height-20,$width-5,$height -20,$acolor);//X轴

  23. imageline($im,25,$height-20,25,2,$acolor);//Y轴
  24. while($i< $num){
  25. imagefilledrectangle($im,$i*($tspace $twidth) 40,$height-$datavalue[$i]-20,$i*($twidth $tspace) $tspace 40,$height-20,$jcolor);//画矩形
  26. imagestring($im,3,$i*($tspace $twidth) 40 $twidth/2,$height-$datavalue[$i]-35,$datavalue[$i],$acolor);//在柱子上面写出值
  27. imagestring($im,3,$i*($tspace $twidth) 40 $twidth/2,$height-15,$dataname[$i],$acolor);//在柱子下面写出值
  28. $i ;

  29. }

  30. while($j < 400/10){
  31. imageline($im,25,($height-20)-$j*8,28,($height-20)-$j*8,$acolor);//画出刻度
  32. imagestring($im,2,5,($height-30)-$j*8,$j*10,$acolor);//标出刻度值
  33. $j = $j 10;
  34. }
  35. imagejpeg($im);
  36. }
  37. $data =array("1"=>25,"2"=>30,"3" =>21 );
  38. createImage($data,40,40,300);
  39. ?>

复制代码


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!