Bar chart PHP histogram implementation code

Source: Internet
Author: User
Also have the question friend can add me qq:460634320, everybody discuss together.
:

Copy the Code code as follows:


function CreateImage ($data, $twidth, $tspace, $height) {
Header ("Content-type:image/jpeg");
$dataname = Array ();
$datavalue = Array (); The value inside the//data
$i = 0;
$j = 0;
$k = 0;
$num = sizeof ($DATA);
foreach ($data as $key = = $val) {
$dataname [] = $key;
$datavalue [] = $val;
}
$width = $num * ($twidth + $tspace) + 20;//Get the width of the image
$im = Imagecreate ($width, $height);//Create Image
$bgcolor = Imagecolorallocate ($im, 255,255,255);//Background color
$jcolor = Imagecolorallocate ($im, 255,255,0);//Background color of Rectangle
$acolor = Imagecolorallocate ($im, 0,0,0);//Line Color
Imageline ($im, $height -20, $width -5, $height -20, $acolor);//x axis
Imageline ($im, $height -20,25,2, $acolor);//y Shaft
while ($i < $num) {
Imagefilledrectangle ($im, $i * ($tspace + $twidth) +40, $height-$datavalue [$i]-20, $i * ($twidth + $tspace) + $tspace +40,$ HEIGHT-20, $jcolor);//Draw a rectangle
Imagestring ($im, 3, $i * ($tspace + $twidth) +40+ $twidth/2, $height-$datavalue [$i]-35, $datavalue [$i], $acolor);// Write a value on a pillar
Imagestring ($im, 3, $i * ($tspace + $twidth) +40+ $twidth/2, $height -15, $dataname [$i], $acolor);//write a value under a pillar
$i + +;
}
while ($j < 400/10) {
Imageline ($im, $height -20)-$j *8,28, ($height -20)-$j *8, $acolor);//Draw a scale
Imagestring ($im, 2,5, ($height -30)-$j *8, $j *10, $acolor);//Mark scale value
$j = $j +10;
}
Imagejpeg ($im);
}
$data =array ("1" =>25, "2" =>30, "3" =>21);
CreateImage ($data, 40,40,300);
?>

The above describes the histogram PHP histogram implementation code, including the bar chart aspect of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.