Happy Boys College 24 hours php GD drawing 24-hour bar chart

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 There are 24 numbers, one can't be less. You can modify the function to judge

Copy the Code code as follows:


/*
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 one = 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 a vertical axis
Imageline ($img, 15,30,15,189, $BC);
Draw the horizontal axis
Imageline ($img, 15,190,750,190, $BC);
Draw a vertical pivot point
For ($i =39, $j =10; $i <189; $i = $i +15, $j-) {
Imageline ($img, $i, $i, $BC);
Imagestring ($img, $i -4, $j. " X ", $BC);
}
Draw a horizontal 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, $x, 192, $BC);
}
Vertical axis Marking
$x = Ceil ($hmax/10);
Imagestring ($img, 2,10,15, "x=". $x, $BC);
Vertical axis Marking
0 Pips
$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 pips
$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 pips
$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 pips
$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 pips
$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 pips
$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 pips
$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 pips
$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 pips
$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 pips
$color = Imagecolorallocate ($img, Mt_rand (0, 255), Mt_rand (0, 255), Mt_rand (0, 255));
Imagefilledrectangle ($img, 301, $h 9,315,189, $color);
Imagestring ($img, 1,301, $h 9-10, $hour [9], $color);
Imagechar ($img, 1,306,195,9, $BC);
10 pips
$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 pips
$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 pips
$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 [n], $color);
Imagestring ($img, 1,394,195,12, $BC);
13 pips
$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 [], $color);
Imagestring ($img, 1,424,195,13, $BC);
14 Pips
$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 pips
$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 pips
$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 Pips
$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 Pips
$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 [], $color);
Imagestring ($img, 1,571,195,18, $BC);
19 Pips
$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 [+], $color);
Imagestring ($img, 1,604,195,19, $BC);
20 pips
$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 Pips
$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 pips
$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 Pips
$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 look after adding a border.
Imagerectangle ($img, 0, 0, 754, 209, $BC);
Imagepng ($IMG);
Imagedestroy ($IMG);
}
$str = isset ($_get[' str '])? $_get[' str ']: "";
if ($STR) {
H24 ($STR);
}
?>


The above introduces the Happy Boys College 24 hours php GD drawing 24-hour bar chart, including the Happy Male Academy 24 hours of content, I hope to be interested in PHP tutorial friends 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.