PHP 원형 차트 통계 코드 사용법

WBOY
풀어 주다: 2016-07-25 08:52:15
원래의
926명이 탐색했습니다.
  1. <
  2. define("ANGLE_STEP", 5) //타원호를 그릴 때 각도 단계 정의
  3. function draw_getdarkcolor( $img,$clr) //$clr에 해당하는 어두운 색상 찾기
  4. {
  5. $rgb = imagecolorsforindex($img,$clr)
  6. return array($rgb["red"]/2 ,$ rgb["green"]/2,$rgb["blue"]/2);
  7. }
  8. function draw_getexy($a, $b, $d) //해당 각도 찾기 $d 타원 위의 점 좌표
  9. {
  10. $d = deg2rad($d)
  11. return array(round($a*Cos($d)), round($b*Sin($d) )) );
  12. function draw_arc($img,$ox,$oy,$a,$b,$sd,$ed,$clr) //타원호 함수
  13. {
  14. $n = ceil(($ed-$sd)/ANGLE_STEP)
  15. $d = $sd
  16. list($x0,$y0) = draw_getexy($a,$b,$d );
  17. for($i=0; $i<$n; $i )
  18. {
  19. $d = ($d ANGLE_STEP)>$ed?$ed:($d ANGLE_STEP);
  20. list($x, $y) = draw_getexy($a, $b, $d)
  21. imageline($img, $x0 $ox, $y0 $oy, $x $ox, $y $ oy, $clr);
  22. $x0 = $x;
  23. $y0 = $y;
  24. }
  25. }
  26. function draw_sector($img, $ox, $oy, $a , $b, $sd, $ed, $clr) //부채 그리기
  27. {
  28. $n = ceil(($ed-$sd)/ANGLE_STEP)
  29. $d = $ sd;
  30. list($x0,$y0) = draw_getexy($a, $b, $d)
  31. imageline($img, $x0 $ox, $y0 $oy, $ox, $oy, $clr) ;
  32. for($i=0; $i<$n; $i )
  33. {
  34. $d = ($d ANGLE_STEP)>$ed?$ed:($d ANGLE_STEP );
  35. list($x, $y) = draw_getexy($a, $b, $d)
  36. imageline($img, $x0 $ox, $y0 $oy, $x $ox, $ y $oy , $clr);
  37. $x0 = $x;
  38. $y0 = $y
  39. }
  40. imageline($img, $x0 $ox, $y0 $oy, $ox , $oy , $clr);
  41. list($x, $y) = draw_getexy($a/2, $b/2, ($d $sd)/2)
  42. imagefill($img, $x $ ox, $y $oy, $clr)
  43. }
  44. function draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd, $ed , $clr ) //3D 섹터
  45. {
  46. draw_sector($img, $ox, $oy, $a, $b, $sd, $ed, $clr)
  47. if($sd< 180)
  48. {
  49. list($R, $G, $B) = draw_getdarkcolor($img, $clr)
  50. $clr=imagecolorallocate($img, $R, $G, $B) ;
  51. if($ed>180) $ed = 180;
  52. list($sx, $sy) = draw_getexy($a,$b,$sd); 🎜> $sy = $oy;
  53. list($ex, $ey) = draw_getexy($a, $b, $ed)
  54. $ex = $ox
  55. $ey = $oy;
  56. imageline($img, $sx, $sy, $sx, $sy $v, $clr)
  57. imageline($img, $ex, $ey, $ex, $ey $v, $clr );
  58. draw_arc($img, $ox, $oy $v, $a, $b, $sd, $ed, $clr)
  59. list($sx, $sy) = draw_getexy($a , $b , ($sd $ed)/2)
  60. $sy = $v/2
  61. $sx = $ox
  62. imagefill($img, $sx, $sy, $clr) ;
  63. }
  64. }
  65. function draw_getindexcolor($img, $clr) //RBG를 인덱스 색상으로
  66. {
  67. $R ​​​​= ($clr>> ;16) & 0xff
  68. $G = ($clr>>8)& 0xff
  69. $B = ($clr) & 0xff
  70. return imagecolorallocate($img, $R, $G , $B)
  71. }
  72. // 메인 함수 그리기 및 그림 출력
  73. // $datLst는 데이터 배열, $datLst는 라벨 배열, $datLst는 색상 배열
  74. // 위의 세 배열은 동일해야 합니다
  75. function draw_img($datLst,$labLst,$clrLst,$a=250,$b=120,$v=20,$font=10)
  76. {
  77. $ox = 5 $a;
  78. $oy = 5 $b;
  79. $fw = imagefontwidth($font)
  80. $fh = imagefontheight($font); datLst);/ /데이터 항목 수
  81. $w = 10 $a*2
  82. $h = 10 $b*2 $v ($fh 2)*$n; 🎜> $img = imagecreate($w, $h);
  83. //RGB를 인덱스 색상으로 변환
  84. for($i=0; $i<$n; $i )
  85. $ clrLst[$i ] = draw_getindexcolor($img,$clrLst[$i]);
  86. $clrbk = imagecolorallocate($img, 0xff, 0xff, 0xff)
  87. $clrt = imagecolorallocate($img) , 0x00, 0x00 , 0x00);
  88. //배경색 채우기
  89. imagefill($img, 0, 0, $clrbk)
  90. //Sum
  91. $tot = 0;
  92. for($i=0; $i<$n; $i )
  93. $tot = $datLst[$i]
  94. $sd = 0; ed = 0;
  95. $ly = 10 $b*2 $v
  96. for($i=0; $i<$n; $i )
  97. {
  98. $sd = $ed;
  99. $ ed = $datLst[$i]/$tot*360;
  100. //둥근 케이크 그리기
  101. draw_sector3d($img, $ox, $oy, $a, $b, $v, $sd , $ed, $clrLst[$i]); //$sd,$ed,$clrLst[$i])
  102. //라벨 그리기
  103. imagefilled직사각형 , 5, $ly , 5 $fw, $ly $fh, $clrLst[$i])
  104. imageRectangle($img, 5, $ly, 5 $fw, $ly $fh, $clrt); 🎜> //이미지 문자열 ($img, $font, 5 2*$fw, $ly, $labLst[$i].":".$datLst[$i]."(".(round(10000*($ datLst[$i] /$tot))/100)."%)", $clrt)
  105. $str = iconv("GB2312", "UTF-8", $labLst[$i] );
  106. ImageTTFText($img, $font, 0, 5 2*$fw, $ly 13, $clrt, "./simsun.ttf", $str.":".$datLst[$i]. "(".( round(10000*($datLst[$i]/$tot))/100)."%)")
  107. $ly = $fh 2
  108. }
  109. //그래픽 출력
  110. header("Content-type: image/png");
  111. //생성된 이미지 출력
  112. $imgFileName = "temp/".time().". png";
  113. imagepng($img,$imgFileName);
  114. echo '';
  115. }
  116. ? >
  117. 코드 복사
  118. 2. 호출 방법:

require_once("piefunction.php")

$datLst = array(10,110,300);
    $labLst = array("좋은 리뷰", "보통 리뷰", "나쁜 리뷰"); //Label
  1. $clrLst = array(0x99ff00, 0xff6666, 0x0099ff)
  2. draw_img( $ datLst,$labLst,$clrLst);
  3. ?>

  4. 코드 복사
  5. 지침: 데이터 수가 후속 라벨 및 색상 수와 일치하는 한 올바른 원형 차트 효과를 출력할 수 있습니다.

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