PHP GD draw 24-hour histogram _php tips

Source: Internet
Author: User
80,250,430,134,35,60,233,90,263,225,120,59,151,677,340,221,550,300,229,97,230,123,133,87 a total of 24 numbers, no less. You can modify the function to judge


Copy Code code as follows:



? Php


/*


24-Hour Bar chart


Author: Taokey


qq:29611705


*/





function H24 ($STR) {





$hour = Explode (",", $str);


$hmax = max ($hour);


$ppix = 150/$hmax;





Calculate the height of a bar chart


$h 0 = 190-$hour [0]* $ppix;


$h 1 = 190-$hour [1]* $ppix;


$h 2 = 190-$hour [2]* $ppix;


$h 3 = 190-$hour [3]* $ppix;


$h 4 = 190-$hour [4]* $ppix;


$h 5 = 190-$hour [5]* $ppix;


$h 6 = 190-$hour [6]* $ppix;


$h 7 = 190-$hour [7]* $ppix;


$h 8 = 190-$hour [8]* $ppix;


$h 9 = 190-$hour [9]* $ppix;


$h = 190-$hour [10]* $ppix;


$h = 190-$hour [11]* $ppix;


$h = 190-$hour [12]* $ppix;


$h = 190-$hour [13]* $ppix;


$h = 190-$hour [14]* $ppix;


$h = 190-$hour [15]* $ppix;


$h = 190-$hour [16]* $ppix;


$h = 190-$hour [17]* $ppix;


$h = 190-$hour [18]* $ppix;


$h = 190-$hour [19]* $ppix;


$h = 190-$hour [20]* $ppix;


$h = 190-$hour [21]* $ppix;


$h = 190-$hour [22]* $ppix;


$h = 190-$hour [23]* $ppix;





Create an img


$img = Imagecreate (755,210);


Background


$BGC = Imagecolorallocate ($img, 245, 250, 254);


Black


$BC = Imagecolorallocate ($img, 0,0,0);


Draw Vertical Axis


Imageline ($img, 15,30,15,189, $BC);


Draw the horizontal axis


Imageline ($img, 15,190,750,190, $BC);





Draw Vertical Axis Point


For ($i =39, $j =10 $i <189; $i = $i +15, $j-) {


Imageline ($img, $i, $i, $BC);


Imagestring ($img, 1,1, $i -4, $j. " X ", $BC);


}





Draw the horizontal axis point


$t = true;


For ($i =31, $j =29 $i <750; $i = $j +1, $j = $j +15) {


if ($t) {


$x = $i;


$t =false;


}else{


$x = $i +1;


$t =true;


}


Imageline ($img, $x, 190, $x, $BC);


}


Vertical axis Marker


$x = Ceil ($hmax/10);


Imagestring ($img, 2,10,15, "x=". $x, $BC);


Vertical axis Marker





0 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, $h 0,45,189, $color);


Imagestring ($img, 1,31, $h 0-10, $hour [0], $color);


Imagechar ($img, 1,36,195,0, $BC);





1 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, $h 1,75,189, $color);


Imagestring ($img, 1,61, $h 1-10, $hour [1], $color);


Imagechar ($img, 1,66,195,1, $BC);





2 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, $h 2,105,189, $color);


Imagestring ($img, 1,91, $h 2-10, $hour [2], $color);


Imagechar ($img, 1,96,195,2, $BC);





3 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 121, $h 3,135,189, $color);


Imagestring ($img, 1,121, $h 3-10, $hour [3], $color);


Imagechar ($img, 1,126,195,3, $BC);





4 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 151, $h 4,165,189, $color);


Imagestring ($img, 1,151, $h 4-10, $hour [4], $color);


Imagechar ($img, 1,156,195,4, $BC);





5 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 181, $h 5,195,189, $color);


Imagestring ($img, 1,181, $h 5-10, $hour [5], $color);


Imagechar ($img, 1,186,195,5, $BC);





6 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 211, $h 6,225,189, $color);


Imagestring ($img, 1,211, $h 6-10, $hour [6], $color);


Imagechar ($img, 1,216,195,6, $BC);





7 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 241, $h 7,255,189, $color);


Imagestring ($img, 1,241, $h 7-10, $hour [7], $color);


Imagechar ($img, 1,246,195,7, $BC);





8 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 271, $h 8,285,189, $color);


Imagestring ($img, 1,271, $h 8-10, $hour [8], $color);


Imagechar ($img, 1,276,195,8, $BC);





9 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, $h 9,315,189, $color);


Imagestring ($img, 1,301, $h 9-10, $hour [9], $color);


Imagechar ($img, 1,306,195,9, $BC);





10 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 331, $h 10,345,189, $color);


Imagestring ($img, 1,331, $h 10-10, $hour [ten], $color);


Imagestring ($img, 1,334,195,10, $BC);





11 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 361, $h 11,375,189, $color);


Imagestring ($img, 1,361, $h 11-10, $hour [one], $color);


Imagestring ($img, 1,364,195,11, $BC);





12 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 391, $h 12,405,189, $color);


Imagestring ($img, 1,391, $h 12-10, $hour [a], $color);


Imagestring ($img, 1,394,195,12, $BC);





13 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 421, $h 13,435,189, $color);


Imagestring ($img, 1,421, $h 13-10, $hour [a], $color);


Imagestring ($img, 1,424,195,13, $BC);





14 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 451, $h 14,465,189, $color);


Imagestring ($img, 1,451, $h 14-10, $hour [], $color);


Imagestring ($img, 1,454,195,14, $BC);





15 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 481, $h 15,495,189, $color);


Imagestring ($img, 1,481, $h 15-10, $hour [], $color);


Imagestring ($img, 1,481,195,15, $BC);





16 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 511, $h 16,525,189, $color);


Imagestring ($img, 1,511, $h 16-10, $hour [], $color);


Imagestring ($img, 1,511,195,16, $BC);





17 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 541, $h 17,555,189, $color);


Imagestring ($img, 1,541, $h 17-10, $hour [], $color);


Imagestring ($img, 1,544,195,17, $BC);





18 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 571, $h 18,585,189, $color);


Imagestring ($img, 1,571, $h 18-10, $hour [a], $color);


Imagestring ($img, 1,571,195,18, $BC);





19 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 601, $h 19,615,189, $color);


Imagestring ($img, 1,601, $h 19-10, $hour [a], $color);


Imagestring ($img, 1,604,195,19, $BC);





20 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 631, $h 20,645,189, $color);


Imagestring ($img, 1,631, $h 20-10, $hour [], $color);


Imagestring ($img, 1,634,195,20, $BC);





21 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 661, $h 21,675,189, $color);


Imagestring ($img, 1,661, $h 21-10, $hour [], $color);


Imagestring ($img, 1,664,195,21, $BC);





22 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 691, $h 22,705,189, $color);


Imagestring ($img, 1,691, $h 22-10, $hour [], $color);


Imagestring ($img, 1,694,195,22, $BC);





23 points


$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));


Imagefilledrectangle ($img, 721, $h 23,735,189, $color);


Imagestring ($img, 1,721, $h 23-10, $hour [], $color);


Imagestring ($img, 1,724,195,23, $BC);





It's not good to see when you add a border.


Imagerectangle ($img, 0, 0, 754, 209, $BC);





Imagepng ($IMG);


Imagedestroy ($IMG);


}


$str = isset ($_get[' str '])? $_get[' str ']: "";


if ($STR) {


H24 ($STR);


}


?>





Related Article

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.