백엔드 개발 PHP 튜토리얼 다양한 그래픽 보고서를 표시할 수 있는 PHP 그림 클래스

다양한 그래픽 보고서를 표시할 수 있는 PHP 그림 클래스

Jul 25, 2016 am 09:11 AM

  1. <?php //이미지 클래스
  2. class ImageReport{
  3. var $X;//이미지 크기 X축
  4. var $Y; / /사진 크기 Y축
  5. var $R;//뒷면 색상 R 값
  6. var $G;//...G.
  7. var $B;//...B.
  8. var $TRANSPARENT;//투명 여부 1 또는 0
  9. var $IMAGE;//이미지 개체
  10. //-------------------
  11. var $ARRAYSPLIT;//값을 구분하는 데 사용되는 기호 지정
  12. var $ITEMARRAY;//값
  13. var $REPORTTYPE;//차트 유형, 1은 세로 열, 2는 가로 열, 3은 폴리라인
  14. var $BORDER;//거리
  15. //------
  16. var $FONTSIZE;//글꼴 크기
  17. var $FONTCOLOR ; //글꼴 색상
  18. var $numX = 1; //X축 시작 스케일 값
  19. var $stepX = 1; //X축 각 스케일 간격 값
  20. // --------파라미터 설정 함수
  21. function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){
  22. $this->X=$SizeX ;
  23. $this->Y=$SizeY
  24. $this->R=$R
  25. $this->B= $B ; $this->TRANSPARENT=$Transparent;
  26. }
  27. function setItem($ArraySplit,$ItemArray,$ReportType,$Border){
  28. $this->ARRAYSPLIT=$ ArraySplit;
  29. $this->ITEMARRAY=$ItemArray;
  30. $this->BORDER=$Border;
  31. }
  32. 함수 ($ FontSize){
  33. $this->FONTSIZE=$FontSize;
  34. }
  35. //X축 스케일 값 설정
  36. function setX($numX = 1, $stepX = 1){
  37. $this->numX = $numX;
  38. $this->stepX = $stepX;
  39. }
  40. //--------------- -Body
  41. function PrintReport(){
  42. //캔버스 크기 생성
  43. $this->IMAGE=ImageCreate($this->X,$this->Y)
  44. // 캔버스 배경색 설정
  45. $Background=ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B)
  46. if($this-&gt ;TRANSPARENT ==="1"){
  47. //배경은 투명합니다
  48. Imagecolortransparent($this->IMAGE,$Background)
  49. }else{
  50. //채울 수 있습니다. 투명하게 하고 싶지 않은 경우 배경색
  51. ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this->Y,$Background)
  52. }
  53. //글꼴 크기 및 색상 매개변수
  54. $this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$ this->B);
  55. 스위치( $this->REPORTTYPE){
  56. 케이스 "0":
  57. 중단
  58. 케이스 "1":
  59. $this->imageColumnS ();
  60. 중단;
  61. 사례 "2":
  62. $this->imageColumnH()
  63. 중단
  64. 사례 "3":
  65. $this->imageLine ();
  66. 중단;
  67. 사례 "4":
  68. $this->imageCircle()
  69. 중단
  70. }
  71. $this->printXY(); 🎜> $this->printAll();
  72. }
  73. //---------XY 좌표축 인쇄
  74. function printXY(){
  75. $rulerY = $ ruleX = "";
  76. //XY 좌표축 그리기*/
  77. $color=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255 -$this->B)
  78. $xx=$this->X/10
  79. $yy=$this->Y-$this->Y/10;
  80. ImageLine ($this->IMAGE,$this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER,$color);//X -축
  81. ImageLine($this->IMAGE ,$this->BORDER,$this->Y-$this->BORDER,$this->X-$this->BORDER,$ this->Y-$this->BORDER, $color);//y축
  82. imagestring($this->IMAGE, $this->FONTSIZE, $this->BORDER-2, $this->Y-$this->BORDER 5 , "0", $color);
  83. //Y축 크기 조정
  84. $rulerY=$this->Y-$this-> BORDER;
  85. $i = 0;
  86. while ($rulerY>$this->BORDER*2){
  87. $rulerY=$rulerY-$this->BORDER; this->IMAGE,$this->BORDER,$ 눈금자Y,$this->BORDER-2,$rulerY,$color)
  88. if($this->REPORTTYPE == 2) {//가로 막대형 차트
  89. imagestring($this- >IMAGE, $this->FONTSIZE, $this->BORDER-10, $rulerY-2-$this->BORDER*($i . 5), $this->numX, $color)
  90. $this->numX = $this->stepX;
  91. }
  92. $i ;
  93. }
  94. // X축 크기 조정
  95. $rulerX=$rulerX $this ->BORDER
  96. $i = 0;
  97. while($rulerX<($this->X-$this-> BORDER*2)){
  98. $rulerX=$rulerX $this ->BORDER
  99. //ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER; 10,10,$color)
  100. ImageLine($this- >IMAGE,$rulerX,$this->Y-$this->BORDER,$rulerX,$this->Y-$this- >BORDER 2,$color);
  101. / /Scale 값
  102. if($this->REPORTTYPE == 1){//세로 막대형 차트
  103. imagestring($this-> IMAGE, $this->FONTSIZE, $rulerX-2 $this- >BORDER*($i .5), $this->Y-$this->BORDER 5, $this->numX, $ color);
  104. $this->numX = $this- >stepX;
  105. }else if($this->REPORTTYPE == 3){//折线图
  106. imagestring($this->IMAGE, $this->FONTSIZE, $rulerX-2, $this->Y-$ this->BORDER 5, $this->numX, $color);
  107. $this->numX = $this->stepX;
  108. }
  109. $i ;
  110. }
  111. }
  112. //--------------- 종 모양 그림
  113. function imageColumnS(){
  114. $item_array=Split($this-> ARRAYSPLIT,$this->ITEMARRAY);
  115. $num=개수($item_array);
  116. $item_max=0;
  117. for ($i=0;$i<$num;$i ){
  118. $item_max=Max($item_max,$item_array[$i]);
  119. }
  120. $xx=$ this->BORDER*2;
  121. //형식 그림
  122. for ($i=0;$i<$num;$i ){
  123. srand((double)microtime()*1000000);
  124. if($ this->R!=255 && $this->G!=255 && $this->B!=255){
  125. $R=Rand($this->R,200);
  126. $G=Rand($this->G,200);
  127. $B=Rand($this->B,200);
  128. }else{
  129. $R=Rand(50,200);
  130. $G=랜드(50,200);
  131. $B=랜드(50,200);
  132. }
  133. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  134. //모양의 높이
  135. $height=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($ item_array[$i]/$item_max);
  136. ImageFilledRectangle($this->IMAGE,$xx,$height,$xx $this->BORDER,$this->Y-$this->BORDER,$color);
  137. ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
  138. //사용于间隔
  139. $xx=$xx $this->BORDER*2;
  140. }
  141. }
  142. //------------ 모양 그림
  143. function imageColumnH(){
  144. $item_array=Split($this->ARRAYSPLIT ,$this->ITEMARRAY);
  145. $num=개수($item_array);
  146. $item_max=0;
  147. for ($i=0;$i<$num;$i ){
  148. $item_max=Max($item_max,$item_array[$i]);
  149. }
  150. $yy=$ this->Y-$this->BORDER*2;
  151. //형식 그림
  152. for ($i=0;$i<$num;$i ){
  153. srand((double)microtime()*1000000);
  154. if($ this->R!=255 && $this->G!=255 && $this->B!=255){
  155. $R=Rand($this->R,200);
  156. $G=Rand($this->G,200);
  157. $B=Rand($this->B,200);
  158. }else{
  159. $R=Rand(50,200);
  160. $G=랜드(50,200);
  161. $B=랜드(50,200);
  162. }
  163. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  164. //형태의 크기
  165. $leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);
  166. $leight = $leight < $this->BORDER ? $this->BORDER : $leight;
  167. ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
  168. ImageString($this->IMAGE,$this->FONTSIZE,$leight 2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
  169. //사용于间隔
  170. $yy=$yy-$this->BORDER*2;
  171. }
  172. }
  173. //--------------- 折线图
  174. function imageLine(){
  175. $item_array=Split($this-> ARRAYSPLIT,$this->ITEMARRAY);
  176. $num=개수($item_array);
  177. $item_max=0;
  178. for ($i=0;$i<$num;$i ){
  179. $item_max=Max($item_max,$item_array[$i]);
  180. }
  181. $xx=$ this->BORDER;
  182. //형식 그림
  183. for ($i=0;$i<$num;$i ){
  184. srand((double)microtime()*1000000);
  185. if($ this->R!=255 && $this->G!=255 && $this->B!=255){
  186. $R=Rand($this->R,200);
  187. $G=Rand($this->G,200);
  188. $B=Rand($this->B,200);
  189. }else{
  190. $R=Rand(50,200);
  191. $G=랜드(50,200);
  192. $B=랜드(50,200);
  193. }
  194. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  195. //모양의 높이
  196. $height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($ item_array[$i]/$item_max);
  197. if($i!="0")
  198. ImageLine($this->IMAGE,$xx-$this->BORDER,$height_next,$xx,$height_now,$color);
  199. ImageString($this->IMAGE,$this->FONTSIZE,$xx 2,$height_now-$this->BORDER/2,$item_array[$i],$this-> 글꼴 색상);
  200. $height_next=$height_now;
  201. //사용于间隔
  202. $xx=$xx $this->BORDER;
  203. }
  204. }
  205. //---------------饼状图
  206. function imageCircle(){
  207. $total = 0;
  208. $ item_array=분할($this->ARRAYSPLIT,$this->ITEMARRAY);
  209. $num=개수($item_array);
  210. $item_max=0;
  211. for ($i=0;$i<$num;$i ){
  212. $item_max=Max($item_max,$item_array[$i]);
  213. $total = $item_array[$i ];
  214. }
  215. $yy=$this->Y-$this->BORDER*2;
  216. //画饼状图的阴影부분분
  217. $e=0;
  218. for ($i=0;$i<$num;$i ){
  219. srand((double )microtime()*1000000);
  220. if($this->R!=255 && $this->G!=255 && $this->B!=255){
  221. $R= 랜드($this->R,200);
  222. $G=Rand($this->G,200);
  223. $B=Rand($this->B,200);
  224. }else{
  225. $R=Rand(50,200);
  226. $G=랜드(50,200);
  227. $B=랜드(50,200);
  228. }
  229. $s=$e;
  230. $leight=$item_array[$i]/$total*360;
  231. $e=$s $leight;
  232. $color=ImageColorAllocate( $this->IMAGE,$R,$G,$B);
  233. $colorarray[$i]=$color;
  234. //画圆
  235. for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $ e, $color, IMG_ARC_PIE);
  236. //imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
  237. //ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
  238. //ImageString($this->IMAGE,$this->FONTSIZE,$leight 2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
  239. //사용于间隔
  240. $yy=$yy-$this->BORDER*2;
  241. }
  242. //画饼状图的表면부분
  243. $e=0;
  244. for ($i=0;$i<$num;$i ){
  245. srand((double)microtime()*1000000);
  246. if($this->R!=255 && $this->G!=255 && $this->B!=255){
  247. $R=Rand($this->R,200);
  248. $G=Rand($this->G,200);
  249. $B=Rand($this->B,200);
  250. }else{
  251. $R=Rand(50,200);
  252. $G=랜드(50,200);
  253. $B=랜드(50,200);
  254. }
  255. $s=$e;
  256. $leight=$item_array[$i]/$total*360;
  257. $e=$s $leight;
  258. //$color= $colorarray[$i];
  259. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  260. //画圆
  261. //for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s , $e, $color, IMG_ARC_PIE);
  262. imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
  263. }
  264. }
  265. //---------------完成打印图shape
  266. function printAll(){
  267. ImagePNG($this->IMAGE) ;
  268. ImageDestroy($this->IMAGE);
  269. }
  270. //-------------调试
  271. function debug(){
  272. echo "X:".$this->X."&lt ;br/>Y:".$this->Y;
  273. echo "<br/>BORDER:".$this->BORDER;
  274. $item_array=split($this->ARRAYSPLIT,$this->ITEMARRAY);
  275. $num=개수($item_array);
  276. echo "<br/>数值个数:".$num."<br/>数值:";
  277. for ($i=0;$i<$num;$i ){
  278. echo "<br/>".$item_array[$i];
  279. }
  280. }
  281. }
  282. //$report->debug();//调式之用
  283. /*
  284. Header( "콘텐츠 유형:이미지/png" );
  285. $report=new ImageReport;
  286. $report->setImage(600,500,255,255,255,1);//参数(长,高,背影colorR,G,B,是否透明1或0)
  287. >符号,数值变weight,样式1为竖柱图2为横柱图3为折线图4为饼图,距离)
  288. $report->setFont(1);//字体大小1-10
  289. / /$report->setX(1,1);//设置X轴刻degree值(起始刻島值=1,刻島间隔值=1)
  290. $report->PrintReport();
  291. * /
  292. ?>
复代码

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) 11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) Mar 03, 2025 am 10:49 AM

11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄)

Laravel의 플래시 세션 데이터로 작업합니다 Laravel의 플래시 세션 데이터로 작업합니다 Mar 12, 2025 pm 05:08 PM

Laravel의 플래시 세션 데이터로 작업합니다

6 PHP 개발자가 가져야 할 6 가지 추가 기술 6 PHP 개발자가 가져야 할 6 가지 추가 기술 Feb 28, 2025 am 10:52 AM

6 PHP 개발자가 가져야 할 6 가지 추가 기술

PHP의 배열을 이해하십시오 PHP의 배열을 이해하십시오 Feb 28, 2025 am 10:53 AM

PHP의 배열을 이해하십시오

Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Mar 12, 2025 pm 05:09 PM

Laravel 테스트에서 단순화 된 HTTP 응답 조롱

Laravel Back End : Part 2, React가있는 React 앱 구축 Laravel Back End : Part 2, React가있는 React 앱 구축 Mar 04, 2025 am 09:33 AM

Laravel Back End : Part 2, React가있는 React 앱 구축

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Mar 13, 2025 pm 12:08 PM

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 Mar 14, 2025 am 11:42 AM

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법

See all articles