最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP生成條形圖的方法

 更新時間:2014年12月10日 14:30:26   投稿:shichen2014  
這篇文章主要介紹了PHP生成條形圖的方法,可實現(xiàn)生成柱狀的條形圖,適用于一些類似柱狀圖顯示報表的場合,具有一定的實用價值,需要的朋友可以參考下

本文實例講述了PHP生成條形圖的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

復(fù)制代碼 代碼如下:

<?php
  // create an array of values for the chart. These values 
  // could come from anywhere, POST, GET, database etc. 
  $values = array(23,32,35,57,12,3,36,54,32,15,43,24,30);
 
  // now we get the number of values in the array. this will 
  // tell us how many columns to plot 
    $columns  = count($values);
 
  // set the height and width of the graph image
 
    $width = 300; 
    $height = 200;
 
  // Set the amount of space between each column 
    $padding = 5;
 
  // Get the width of 1 column 
    $column_width = $width / $columns ;
 
  // set the graph color variables 
    $im        = imagecreate($width,$height); 
    $gray      = imagecolorallocate ($im,0xcc,0xcc,0xcc); 
    $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee); 
    $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f); 
    $white     = imagecolorallocate ($im,0xff,0xff,0xff);
 
  // set the background color of the graph 
    imagefilledrectangle($im,0,0,$width,$height,$white);
 
 
  // Calculate the maximum value we are going to plot 
  $max_value = max($values);
 
  // loop over the array of columns 
    for($i=0;$i<$columns;$i++) 
        {
    // set the column hieght for each value 
        $column_height = ($height / 100) * (( $values[$i] / $max_value)
 
*100); 
    // now the coords
        $x1 = $i*$column_width; 
        $y1 = $height-$column_height; 
        $x2 = (($i+1)*$column_width)-$padding; 
        $y2 = $height;
 
        // write the columns over the background 
        imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);
 
        // This gives the columns a little 3d effect 
        imageline($im,$x1,$y1,$x1,$y2,$gray_lite); 
        imageline($im,$x1,$y2,$x2,$y2,$gray_lite); 
        imageline($im,$x2,$y1,$x2,$y2,$gray_dark); 
        }
 
   // set the correct png headers 
   header ("Content-type: image/png"); 
  // spit the image out the other end 
  imagepng($im); 
?>

運(yùn)行效果如下圖所示:

希望本文所述對大家的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論

通道| 友谊县| 通渭县| 通州区| 犍为县| 多伦县| 孟津县| 漠河县| 望谟县| 沙雅县| 建始县| 图木舒克市| 五河县| 隆德县| 无锡市| 澄迈县| 房产| 江西省| 高陵县| 屏南县| 通河县| 沂源县| 迭部县| 阿拉善左旗| 葵青区| 城口县| 刚察县| 双牌县| 河池市| 衡东县| 广水市| 都江堰市| 额尔古纳市| 互助| 治多县| 洛浦县| 富锦市| 察隅县| 米易县| 壤塘县| 巴马|