国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

PHP生成條形圖

2024-09-04 11:44:33
字體:
來源:轉載
供稿:網友
  1. <?php 
  2.  
  3.   // create an array of values for the chart. These values  
  4.   // could come from anywhere, POST, GET, database etc.  
  5.   $values = array(23,32,35,57,12,3,36,54,32,15,43,24,30); 
  6.  
  7.   // now we get the number of values in the array. this will  
  8.   // tell us how many columns to plot  
  9.     $columns  = count($values); 
  10.  
  11.   // set the height and width of the graph image 
  12.  
  13.     $width = 300;  
  14.     $height = 200; 
  15.  
  16.   // Set the amount of space between each column  
  17.     $padding = 5; 
  18.  
  19.   // Get the width of 1 column  
  20.     $column_width = $width / $columns ; 
  21.  
  22.   // set the graph color variables  
  23.     $im        = imagecreate($width,$height);  
  24.     $gray      = imagecolorallocate ($im,0xcc,0xcc,0xcc);  
  25.     $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);  
  26.     $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);  
  27.     $white     = imagecolorallocate ($im,0xff,0xff,0xff); 
  28.  
  29.   // set the background color of the graph  
  30.     imagefilledrectangle($im,0,0,$width,$height,$white); 
  31.  
  32.  
  33.   // Calculate the maximum value we are going to plot  
  34.   $max_value = max($values); 
  35.  
  36.   // loop over the array of columns  
  37.     for($i=0;$i<$columns;$i++)  
  38.         { 
  39.     // set the column hieght for each value  
  40.         $column_height = ($height / 100) * (( $values[$i] / $max_value
  41.  
  42. *100);  
  43.     // now the coords 
  44.         $x1 = $i*$column_width;  
  45.         $y1 = $height-$column_height;  
  46.         $x2 = (($i+1)*$column_width)-$padding;  
  47.         $y2 = $height
  48.  
  49.         // write the columns over the background  
  50.         imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray); 
  51.  
  52.         // This gives the columns a little 3d effect  
  53.         imageline($im,$x1,$y1,$x1,$y2,$gray_lite);  
  54.         imageline($im,$x1,$y2,$x2,$y2,$gray_lite);  
  55.         imageline($im,$x2,$y1,$x2,$y2,$gray_dark);  
  56.         } 
  57.  
  58.    // set the correct png headers  
  59.    //開源代碼Vevb.com 
  60.    header ("Content-type: image/png");  
  61.   // spit the image out the other end  
  62.   imagepng($im);  
  63. ?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平顶山市| 阳高县| 满城县| 伊金霍洛旗| 潮州市| 四子王旗| 梁河县| 谷城县| 许昌县| 简阳市| 新余市| 拜泉县| 绥化市| 延庆县| 镇雄县| 马龙县| 全州县| 土默特右旗| 会昌县| 施甸县| 潼关县| 海兴县| 阿拉尔市| 海丰县| 昌平区| 香港 | 灵石县| 曲靖市| 安陆市| 资兴市| 雷波县| 若羌县| 禄劝| 安平县| 塘沽区| 普定县| 蕲春县| 永年县| 铅山县| 九龙县| 沿河|