PHP的產生橫條圖_PHP教程

來源:互聯網
上載者:User
PHP的產生橫條圖
由於overwhelmning為廣東的需求有關的例子,這個最重要的是產生從一個數組橫條圖要

求。當然,這些可以很容易地從任何來源數目,以及投入到一個數組


// 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);
?>


http://www.bkjia.com/PHPjc/444988.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444988.htmlTechArticlePHP的產生橫條圖 由於overwhelmning為廣東的需求有關的例子,這個最重要的是產生從一個數組橫條圖要 求。當然,這些可以很容易地從任何來...

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.