欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP生成條形圖的方法

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

本文實(shí)例講述了PHP生成條形圖的方法。分享給大家供大家參考。具體實(shí)現(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)行效果如下圖所示:

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

相關(guān)文章

  • 提高php運(yùn)行速度的一些小技巧分享

    提高php運(yùn)行速度的一些小技巧分享

    使用PHP的最大1個(gè)優(yōu)勢(shì)就是速度快。一般情況下,PHP總是具有足夠的速度支持Web內(nèi)容動(dòng)態(tài)生成,許多時(shí)候甚至無法找出比它更快的方法。然而,當(dāng)面對(duì)龐大的訪問量、高負(fù)荷的應(yīng)用、有限的帶寬,以及其他各種帶來性能瓶頸的因素時(shí),就需要考慮怎樣提高PHP的性能了
    2012-07-07
  • php操作access數(shù)據(jù)庫(kù)的方法詳解

    php操作access數(shù)據(jù)庫(kù)的方法詳解

    這篇文章主要介紹了php操作access數(shù)據(jù)庫(kù)的方法,結(jié)合實(shí)例形式詳細(xì)分析了php基于ADOdb、PDO及ODBC等方式連接與操作access數(shù)據(jù)庫(kù)的具體實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2017-02-02
  • PHP中常用的字符串格式化函數(shù)總結(jié)

    PHP中常用的字符串格式化函數(shù)總結(jié)

    這篇文章主要介紹了PHP中常用的字符串格式化函數(shù)總結(jié),本文講解的函數(shù)是WEB中經(jīng)常用到的,例如取出空格和字符串填補(bǔ)函數(shù)、字符串大小寫的轉(zhuǎn)換、和HTML標(biāo)簽相關(guān)的字符串格式化等,需要的朋友可以參考下
    2014-11-11
  • PHP+Tidy-完美的XHTML糾錯(cuò)+過濾

    PHP+Tidy-完美的XHTML糾錯(cuò)+過濾

    PHP+Tidy-完美的XHTML糾錯(cuò)+過濾...
    2007-04-04
  • PHP二維數(shù)組排序簡(jiǎn)單實(shí)現(xiàn)方法

    PHP二維數(shù)組排序簡(jiǎn)單實(shí)現(xiàn)方法

    這篇文章主要介紹了PHP二維數(shù)組排序簡(jiǎn)單實(shí)現(xiàn)方法,涉及PHP針對(duì)數(shù)組的遍歷與排序操作常用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-02-02
  • 8個(gè)PHP數(shù)組面試題

    8個(gè)PHP數(shù)組面試題

    這篇文章主要介紹了8個(gè)PHP數(shù)組面試題,例如寫函數(shù)創(chuàng)建長(zhǎng)度為10的數(shù)組,數(shù)組中的元素為遞增的奇數(shù),首項(xiàng)為1、創(chuàng)建長(zhǎng)度為10的數(shù)組,數(shù)組中的數(shù)為遞增的等比數(shù),比值為3,首項(xiàng)為等題目,需要的朋友可以參考下
    2015-06-06
  • php獲取服務(wù)器信息的實(shí)現(xiàn)代碼

    php獲取服務(wù)器信息的實(shí)現(xiàn)代碼

    php獲取服務(wù)器信息的一段代碼,包括獲取mysql數(shù)據(jù)庫(kù)版本信息、GD庫(kù)信息、php上傳相關(guān)信息等。有需要的朋友,可以參考下
    2013-02-02
  • php5中date()得出的時(shí)間為什么不是當(dāng)前時(shí)間的解決方法

    php5中date()得出的時(shí)間為什么不是當(dāng)前時(shí)間的解決方法

    從php5.10開始,php中加入了時(shí)區(qū)的設(shè)置,在php中顯示的時(shí)間都是格林威治標(biāo)準(zhǔn)時(shí)間,這就造成了我們 中國(guó)的用戶會(huì)差八個(gè)小時(shí)的問題!
    2008-06-06
  • PHP 開發(fā)環(huán)境配置(Zend Server安裝)

    PHP 開發(fā)環(huán)境配置(Zend Server安裝)

    運(yùn)行安裝文件(ZendServer-CE-php-5.3.2-5.0.1-Windows_x86.exe)開始安裝,選項(xiàng)請(qǐng)參照我的選擇。
    2010-04-04
  • phpmyadmin中配置文件現(xiàn)在需要絕密的短語密碼的解決方法

    phpmyadmin中配置文件現(xiàn)在需要絕密的短語密碼的解決方法

    phpmyadmin中配置文件現(xiàn)在需要絕密的短語密碼的解決方法...
    2007-02-02

最新評(píng)論