国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial PHP picture class that can display a variety of graphical reports

PHP picture class that can display a variety of graphical reports

Jul 25, 2016 am 09:11 AM

  1. class ImageReport{
  2. var $X;//Picture size X-axis
  3. var $Y;//Picture size Y-axis
  4. var $R;//Back color R value
  5. var $G;//...G.
  6. var $B;//...B.
  7. var $TRANSPARENT;//Whether it is transparent 1 or 0
  8. var $IMAGE;//Image object
  9. //- ------------------
  10. var $ARRAYSPLIT;//Specify the symbol used to separate values ??
  11. var $ITEMARRAY;//Value
  12. var $REPORTTYPE;//Chart type, 1 is a vertical column, 2 is a horizontal column, 3 is a polyline shape
  13. var $BORDER;//distance
  14. //-------------------
  15. var $FONTSIZE;/ /Font size
  16. var $FONTCOLOR;//Font color
  17. var $numX = 1;//X-axis starting scale value
  18. var $stepX = 1;//X-axis each scale interval value
  19. //-- ------Parameter setting function
  20. function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){
  21. $this->X=$SizeX;
  22. $this->Y =$SizeY;
  23. $this->R=$R;
  24. $this->G=$G;
  25. $this->B=$B;
  26. $this->TRANSPARENT=$Transparent;
  27. }
  28. function setItem($ArraySplit,$ItemArray,$ReportType,$Border){
  29. $this->ARRAYSPLIT=$ArraySplit;
  30. $this->ITEMARRAY=$ItemArray;
  31. $this->REPORTTYPE=$ReportType;
  32. $this->BORDER=$Border;
  33. }
  34. function setFont($FontSize){
  35. $this->FONTSIZE=$FontSize;
  36. }
  37. //X-axis scale value setting
  38. function setX($numX = 1 , $stepX = 1){
  39. $this->numX = $numX;
  40. $this->stepX = $stepX;
  41. }
  42. //---------------- Main body
  43. function PrintReport(){
  44. //Create canvas size
  45. $this->IMAGE=ImageCreate($this->X,$this->Y);
  46. //Set canvas background color
  47. $background= ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B);
  48. if($this->TRANSPARENT=="1"){
  49. // The background is transparent
  50. Imagecolortransparent($this->IMAGE,$background);
  51. }else{
  52. //If you don’t want to make it transparent, you can fill it with the background color
  53. ImageFilledRectangle($this->IMAGE,0,0,$this-> X,$this->Y,$background);
  54. }
  55. //Parameter font size and color
  56. $this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R, 255-$this->G,255-$this->B);
  57. Switch ($this->REPORTTYPE){
  58. case "0":
  59. break;
  60. case "1":
  61. $this-> ;imageColumnS();
  62. break;
  63. case "2":
  64. $this->imageColumnH();
  65. break;
  66. case "3":
  67. $this->imageLine();
  68. break;
  69. case "4 ":
  70. $this->imageCircle();
  71. break;
  72. }
  73. $this->printXY();
  74. $this->printAll();
  75. }
  76. //-------- ---Print the XY coordinate axis
  77. function printXY(){
  78. $rulerY = $rulerX = "";
  79. //Draw the XY coordinate axis*/
  80. $color=ImageColorAllocate($this->IMAGE,255-$this- >R,255-$this->G,255-$this->B);
  81. $xx=$this->X/10;
  82. $yy=$this->Y-$this- >Y/10;
  83. ImageLine($this->IMAGE,$this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER ,$color);//X axis
  84. ImageLine($this->IMAGE,$this->BORDER,$this->Y-$this->BORDER,$this->X-$this- >BORDER,$this->Y-$this->BORDER,$color);//y-axis
  85. imagestring($this->IMAGE, $this->FONTSIZE, $this->BORDER- 2, $this->Y-$this->BORDER+5, "0", $color);
  86. //Scale on Y axis
  87. $rulerY=$this->Y-$this->BORDER ;
  88. $i = 0;
  89. while($rulerY>$this->BORDER*2){
  90. $rulerY=$rulerY-$this->BORDER;
  91. ImageLine($this->IMAGE,$this- >BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);
  92. if($this->REPORTTYPE == 2){//Horizontal column chart
  93. imagestring($this-> ;IMAGE, $this->FONTSIZE, $this->BORDER-10, $rulerY-2-$this->BORDER*($i+.5), $this->numX, $color);
  94. $this->numX += $this->stepX;
  95. }
  96. $i++;
  97. }
  98. //Scale on the while($rulerX<($this->X-$this->BORDER*2)){
  99. $rulerX=$rulerX+$this->BORDER;
  100. //ImageLine($this->IMAGE,$ this->BORDER,10,$this->BORDER+10,10,$color);
  101. ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BORDER, $rulerX,$this->Y-$this->BORDER+2,$color);
  102. //Scale value
  103. if($this->REPORTTYPE == 1){//Vertical column chart
  104. imagestring ($this->IMAGE, $this->FONTSIZE, $rulerX-2+$this->BORDER*($i+.5), $this->Y-$this->BORDER+5, $this->numX, $color);
  105. $this->numX += $this->stepX;
  106. }else if($this->REPORTTYPE == 3){//折線圖
  107. imagestring($this->IMAGE, $this->FONTSIZE, $rulerX-2, $this->Y-$this->BORDER+5, $this->numX, $color);
  108. $this->numX += $this->stepX;
  109. }
  110. $i++;
  111. }
  112. }
  113. //--------------豎柱形圖
  114. function imageColumnS(){
  115. $item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
  116. $num=Count($item_array);
  117. $item_max=0;
  118. for ($i=0;$i<$num;$i++){
  119. $item_max=Max($item_max,$item_array[$i]);
  120. }
  121. $xx=$this->BORDER*2;
  122. //畫柱形圖
  123. for ($i=0;$i<$num;$i++){
  124. srand((double)microtime()*1000000);
  125. if($this->R!=255 && $this->G!=255 && $this->B!=255){
  126. $R=Rand($this->R,200);
  127. $G=Rand($this->G,200);
  128. $B=Rand($this->B,200);
  129. }else{
  130. $R=Rand(50,200);
  131. $G=Rand(50,200);
  132. $B=Rand(50,200);
  133. }
  134. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  135. //柱形高度
  136. $height=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
  137. ImageFilledRectangle($this->IMAGE,$xx,$height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color);
  138. ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
  139. //用于間隔
  140. $xx=$xx+$this->BORDER*2;
  141. }
  142. }
  143. //-----------橫柱形圖
  144. function imageColumnH(){
  145. $item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
  146. $num=Count($item_array);
  147. $item_max=0;
  148. for ($i=0;$i<$num;$i++){
  149. $item_max=Max($item_max,$item_array[$i]);
  150. }
  151. $yy=$this->Y-$this->BORDER*2;
  152. //畫柱形圖
  153. for ($i=0;$i<$num;$i++){
  154. srand((double)microtime()*1000000);
  155. if($this->R!=255 && $this->G!=255 && $this->B!=255){
  156. $R=Rand($this->R,200);
  157. $G=Rand($this->G,200);
  158. $B=Rand($this->B,200);
  159. }else{
  160. $R=Rand(50,200);
  161. $G=Rand(50,200);
  162. $B=Rand(50,200);
  163. }
  164. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  165. //柱形長度
  166. $leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);
  167. $leight = $leight < $this->BORDER ? $this->BORDER : $leight;
  168. ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
  169. ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
  170. //用于間隔
  171. $yy=$yy-$this->BORDER*2;
  172. }
  173. }
  174. //--------------折線圖
  175. function imageLine(){
  176. $item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
  177. $num=Count($item_array);
  178. $item_max=0;
  179. for ($i=0;$i<$num;$i++){
  180. $item_max=Max($item_max,$item_array[$i]);
  181. }
  182. $xx=$this->BORDER;
  183. //畫柱形圖
  184. for ($i=0;$i<$num;$i++){
  185. srand((double)microtime()*1000000);
  186. if($this->R!=255 && $this->G!=255 && $this->B!=255){
  187. $R=Rand($this->R,200);
  188. $G=Rand($this->G,200);
  189. $B=Rand($this->B,200);
  190. }else{
  191. $R=Rand(50,200);
  192. $G=Rand(50,200);
  193. $B=Rand(50,200);
  194. }
  195. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  196. //柱形高度
  197. $height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);
  198. if($i!="0")
  199. ImageLine($this->IMAGE,$xx-$this->BORDER,$height_next,$xx,$height_now,$color);
  200. ImageString($this->IMAGE,$this->FONTSIZE,$xx+2,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR);
  201. $height_next=$height_now;
  202. //用于間隔
  203. $xx=$xx+$this->BORDER;
  204. }
  205. }
  206. //--------------餅狀圖
  207. function imageCircle(){
  208. $total = 0;
  209. $item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
  210. $num=Count($item_array);
  211. $item_max=0;
  212. for ($i=0;$i<$num;$i++){
  213. $item_max=Max($item_max,$item_array[$i]);
  214. $total += $item_array[$i];
  215. }
  216. $yy=$this->Y-$this->BORDER*2;
  217. //畫餅狀圖的陰影部分
  218. $e=0;
  219. for ($i=0;$i<$num;$i++){
  220. srand((double)microtime()*1000000);
  221. if($this->R!=255 && $this->G!=255 && $this->B!=255){
  222. $R=Rand($this->R,200);
  223. $G=Rand($this->G,200);
  224. $B=Rand($this->B,200);
  225. }else{
  226. $R=Rand(50,200);
  227. $G=Rand(50,200);
  228. $B=Rand(50,200);
  229. }
  230. $s=$e;
  231. $leight=$item_array[$i]/$total*360;
  232. $e=$s+$leight;
  233. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  234. $colorarray[$i]=$color;
  235. //畫圓
  236. for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $e, $color, IMG_ARC_PIE);
  237. //imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
  238. //ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
  239. //ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
  240. //用于間隔
  241. $yy=$yy-$this->BORDER*2;
  242. }
  243. //畫餅狀圖的表面部分
  244. $e=0;
  245. for ($i=0;$i<$num;$i++){
  246. srand((double)microtime()*1000000);
  247. if($this->R!=255 && $this->G!=255 && $this->B!=255){
  248. $R=Rand($this->R,200);
  249. $G=Rand($this->G,200);
  250. $B=Rand($this->B,200);
  251. }else{
  252. $R=Rand(50,200);
  253. $G=Rand(50,200);
  254. $B=Rand(50,200);
  255. }
  256. $s=$e;
  257. $leight=$item_array[$i]/$total*360;
  258. $e=$s+$leight;
  259. //$color=$colorarray[$i];
  260. $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
  261. //畫圓
  262. //for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $e, $color, IMG_ARC_PIE);
  263. imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
  264. }
  265. }
  266. //--------------完成打印圖形
  267. function printAll(){
  268. ImagePNG($this->IMAGE);
  269. ImageDestroy($this->IMAGE);
  270. }
  271. //--------------調試
  272. function debug(){
  273. echo "X:".$this->X."
    Y:".$this->Y;
  274. echo "
    BORDER:".$this->BORDER;
  275. $item_array=split($this->ARRAYSPLIT,$this->ITEMARRAY);
  276. $num=Count($item_array);
  277. echo "
    數(shù)值個數(shù):".$num."
    數(shù)值:";
  278. for ($i=0;$i<$num;$i++){
  279. echo "
    ".$item_array[$i];
  280. }
  281. }
  282. }
  283. //$report->debug();//調式之用
  284. /*
  285. Header( "Content-type:image/png");
  286. $report=new ImageReport;
  287. $report->setImage(600,500,255,255,255,1);//參數(shù)(長,高,背影色R,G,B,是否透明1或0)
  288. $temparray="0,260,400,124,48,720,122,440,475";//數(shù)值,用指定符號隔開
  289. $report->setItem(',',$temparray,3,23);//參數(shù)(分隔數(shù)值的指定符號,數(shù)值變量,樣式1為豎柱圖2為橫柱圖3為折線圖4為餅圖,距離)
  290. $report->setFont(1);//字體大小1-10
  291. //$report->setX(1,1);//設置X軸刻度值(起始刻度值=1,刻度間隔值=1)
  292. $report->PrintReport();
  293. */
  294. ?>
復制代碼


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
PHP Variable Scope Explained PHP Variable Scope Explained Jul 17, 2025 am 04:16 AM

Common problems and solutions for PHP variable scope include: 1. The global variable cannot be accessed within the function, and it needs to be passed in using the global keyword or parameter; 2. The static variable is declared with static, and it is only initialized once and the value is maintained between multiple calls; 3. Hyperglobal variables such as $_GET and $_POST can be used directly in any scope, but you need to pay attention to safe filtering; 4. Anonymous functions need to introduce parent scope variables through the use keyword, and when modifying external variables, you need to pass a reference. Mastering these rules can help avoid errors and improve code stability.

How to handle File Uploads securely in PHP? How to handle File Uploads securely in PHP? Jul 08, 2025 am 02:37 AM

To safely handle PHP file uploads, you need to verify the source and type, control the file name and path, set server restrictions, and process media files twice. 1. Verify the upload source to prevent CSRF through token and detect the real MIME type through finfo_file using whitelist control; 2. Rename the file to a random string and determine the extension to store it in a non-Web directory according to the detection type; 3. PHP configuration limits the upload size and temporary directory Nginx/Apache prohibits access to the upload directory; 4. The GD library resaves the pictures to clear potential malicious data.

Commenting Out Code in PHP Commenting Out Code in PHP Jul 18, 2025 am 04:57 AM

There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.

How Do Generators Work in PHP? How Do Generators Work in PHP? Jul 11, 2025 am 03:12 AM

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

Tips for Writing PHP Comments Tips for Writing PHP Comments Jul 18, 2025 am 04:51 AM

The key to writing PHP comments is to clarify the purpose and specifications. Comments should explain "why" rather than "what was done", avoiding redundancy or too simplicity. 1. Use a unified format, such as docblock (/*/) for class and method descriptions to improve readability and tool compatibility; 2. Emphasize the reasons behind the logic, such as why JS jumps need to be output manually; 3. Add an overview description before complex code, describe the process in steps, and help understand the overall idea; 4. Use TODO and FIXME rationally to mark to-do items and problems to facilitate subsequent tracking and collaboration. Good annotations can reduce communication costs and improve code maintenance efficiency.

Learning PHP: A Beginner's Guide Learning PHP: A Beginner's Guide Jul 18, 2025 am 04:54 AM

TolearnPHPeffectively,startbysettingupalocalserverenvironmentusingtoolslikeXAMPPandacodeeditorlikeVSCode.1)InstallXAMPPforApache,MySQL,andPHP.2)Useacodeeditorforsyntaxsupport.3)TestyoursetupwithasimplePHPfile.Next,learnPHPbasicsincludingvariables,ech

How to access a character in a string by index in PHP How to access a character in a string by index in PHP Jul 12, 2025 am 03:15 AM

In PHP, you can use square brackets or curly braces to obtain string specific index characters, but square brackets are recommended; the index starts from 0, and the access outside the range returns a null value and cannot be assigned a value; mb_substr is required to handle multi-byte characters. For example: $str="hello";echo$str[0]; output h; and Chinese characters such as mb_substr($str,1,1) need to obtain the correct result; in actual applications, the length of the string should be checked before looping, dynamic strings need to be verified for validity, and multilingual projects recommend using multi-byte security functions uniformly.

Quick PHP Installation Tutorial Quick PHP Installation Tutorial Jul 18, 2025 am 04:52 AM

ToinstallPHPquickly,useXAMPPonWindowsorHomebrewonmacOS.1.OnWindows,downloadandinstallXAMPP,selectcomponents,startApache,andplacefilesinhtdocs.2.Alternatively,manuallyinstallPHPfromphp.netandsetupaserverlikeApache.3.OnmacOS,installHomebrew,thenrun'bre

See all articles