PHP Histogram Generation class Code _php tutorial

Source: Internet
Author: User
PHP histogram generate class Code//This is a perfect PHP histogram generated class code, you can generate beautiful and practical bar chart

PHP Tutorial histogram generate class Code
This is a perfect PHP histogram generated class code, you can generate beautiful and practical bar chart

function CreateImage ($data, $twidth, $tspace, $height) {
$dataname = Array ();
$datavalue = Array ();
$i = 0;
$j = 0;
$k = 0;
$num = sizeof ($DATA);

foreach ($data as $key = = $val) {
$dataname [] = $key;
$datavalue [] = $val;
}

$maxnum = max ($data);
$width = ($twidth + $tspace) * $num + 4;//image ' s width
$im = imagecreate ($width + +, $height +20);
$linecolor = Imagecolorallocate ($im, 12,12,12);
$bgcolor = Imagecolorallocate ($im, 235,233,233);
$tcolor = Imagecolorallocate ($im, 123,200,56);
Imagefill ($im, 0,0, $bgcolor);
Imageline ($im, 0, $height-2, $linecolor);
Imageline ($im, $height-2, $width + 30-2, $height-2, $linecolor);
while ($i < $num) {
Imagefilledrectangle ($im, $i * ($tspace + $twidth) +, $height-$datavalue [$i], $i * ($tspace + $twidth) + + + $twidth, $height -3, $tcolor);
Imagestringup ($im, 4, $i * ($tspace + $twidth) + $twidth/2 +, $height -10, $dataname [$i]. " (". $datavalue [$i].") ", $linecolor);
$i + +;
}
while ($j <= (500/10)) {
Imagestringup ($im, 4, 2, $height-$j * + ten, $j *, $linecolor);
$j = $j + 10;
}
while ($k <= (500/10)) {
if ($k! = 0)
Imageline ($im, $height-$k *, $height-$k *, $linecolor);
$k = $k + 10;
}
Imagepng ($im);
}

Call Method:

header ("Content-type:image/png");
$data = Array ("Yahoo" + +, "google" = 260, "Microsoft" + +, "IBM" = 290, "Sun system", "inter" = > 260);
CreateImage ($data, 38,25,460);

http://www.bkjia.com/PHPjc/633041.html www.bkjia.com true http://www.bkjia.com/PHPjc/633041.html techarticle PHP Histogram generated class code//This is a perfect PHP histogram generated class code, you can generate beautiful and practical histogram PHP tutorial histogram generated class code//This is a perfect PHP columnar ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.