国产探花免费观看_亚洲丰满少妇自慰呻吟_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. ?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桃江县| 榆树市| 高雄市| 达尔| 乐陵市| 四子王旗| 溧水县| 绥芬河市| 贵定县| 凌源市| 荆州市| 三亚市| 阿坝| 潞城市| 皋兰县| 武穴市| 朝阳市| 县级市| 宁阳县| 英德市| 浦江县| 乐东| 郴州市| 阜南县| 彭山县| 内江市| 体育| 沙田区| 调兵山市| 长宁区| 仁布县| 建德市| 瑞安市| 深水埗区| 湄潭县| 大安市| 香格里拉县| 临汾市| 海口市| 息烽县| 开远市|