80,250,430,134, 263,225,120, 59,151,677,340,221,550,300,229, 97,230,123,133, 87, a total of 24 numbers can be less than one. If there is no error, you can modify the function to determine
CopyCode The Code is as follows: <? PHP
/*
24-hour column chart
Author: taokey
QQ: 29611705
*/
Function h24 ($ Str ){
$ Hour = explode (",", $ Str );
$ Hmax = max ($ hour );
$ Ppix = 150/$ hmax;
// calculate the bar chart height
$ h0 = 190-$ hour [0] * $ ppix;
$ H1 = 190-$ hour [1] * $ ppix;
$ H2 = 190-$ hour [2] * $ ppix;
$ h3 = 190-$ hour [3] * $ ppix;
$ h4 = 190-$ hour [4] * $ ppix;
$ h5 = 190-$ hour [5] * $ ppix;
$ h6 = 190-$ hour [6] * $ ppix;
$ H7 = 190-$ hour [7] * $ ppix;
$ h8 = 190-$ hour [8] * $ ppix;
$ H9 = 190-$ hour [9] * $ ppix;
$ H10 = 190-$ hour [10] * $ ppix;
$ H11 = 190-$ hour [11] * $ ppix;
$ H12 = 190-$ hour [12] * $ ppix;
$ H13 = 190-$ hour [13] * $ ppix;
$ H14 = 190-$ hour [14] * $ ppix;
$ H15 = 190-$ hour [15] * $ ppix;
$ H16 = 190-$ hour [16] * $ ppix;
$ H17 = 190-$ hour [17] * $ ppix;
$ H18 = 190-$ hour [18] * $ ppix;
$ H19 = 190-$ hour [19] * $ ppix;
$ H20 = 190-$ hour [20] * $ ppix;
$ h21 = 190-$ hour [21] * $ ppix;
$ H2 = 190-$ hour [22] * $ ppix;
$ H23 = 190-$ hour [23] * $ ppix;
// Create an IMG
$ IMG = imagecreate (755,210 );
// Background
$ BGC = imagecolorallocate ($ IMG, 245,250,254 );
// Black
$ BC = imagecolorallocate ($ IMG, 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 axis
For ($ I = 39, $ J = 10; $ I <189; $ I = $ I + 15, $ j --){
Imageline ($ IMG, 13, $ I, 15, $ I, $ BC );
Imagestring ($ IMG, $ I-4, $ J. "X", $ BC );
}
// Draw a horizontal axis
$ T = true;
For ($ I = 31, $ J = 29; I 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, 192, $ BC );
}
// Vertical axis marker
$ X = Ceil ($ hmax/10 );
Imagestring ($ IMG, 2,10, 15, "x =". $ X, $ BC );
// Vertical axis marker
// 0
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 31, $ H0, 45,189, $ color );
Imagestring ($ IMG, $ h0-10, $ hour [0], $ color );
Imagechar ($ IMG, 1, 36, 195, 0, $ BC );
// 1 point
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 61, $ H1, 75,189, $ color );
Imagestring ($ IMG, $ h1-10, $ hour [1], $ color );
Imagechar ($ IMG, 1, 66, 195, 1, $ BC );
// 2:
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 91, $ H2, 105,189, $ color );
Imagestring ($ IMG, $ h2-10, $ hour [2], $ color );
Imagechar ($ IMG, 1, 96, 195, 2, $ BC );
// 3 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 121, $ H3, 135,189, $ color );
Imagestring ($ IMG, 1,121, $ h3-10, $ hour [3], $ color );
Imagechar ($ IMG, 1,126,195, 3, $ BC );
// 4 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 151, $ H4, 165,189, $ color );
Imagestring ($ IMG, 1,151, $ h4-10, $ hour [4], $ color );
Imagechar ($ IMG, 1,156,195, 4, $ BC );
// 5 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 181, $ H5, 195,189, $ color );
Imagestring ($ IMG, 1,181, $ h5-10, $ hour [5], $ color );
Imagechar ($ IMG, 1,186,195, 5, $ BC );
// 6 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 211, $ H6, 225,189, $ color );
Imagestring ($ IMG, 1,211, $ h6-10, $ hour [6], $ color );
Imagechar ($ IMG, 1,216,195, 6, $ BC );
// 7 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 241, $ H7, 255,189, $ color );
Imagestring ($ IMG, 1,241, $ h7-10, $ hour [7], $ color );
Imagechar ($ IMG, 1,246,195, 7, $ BC );
// 8 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 271, $ H8, 285,189, $ color );
Imagestring ($ IMG, 1,271, $ h8-10, $ hour [8], $ color );
Imagechar ($ IMG, 1,276,195, 8, $ BC );
// 9 o'
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 301, $ H9, 315,189, $ color );
Imagestring ($ IMG, 1,301, $ h9-10, $ hour [9], $ color );
Imagechar ($ IMG, 1,306,195, 9, $ BC );
// 10 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 331, $ H10, 345,189, $ color );
Imagestring ($ IMG, 1,331, $ h10-10, $ hour [10], $ color );
Imagestring ($ IMG, 1,334,195, 10, $ BC );
// 11 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 361, $ H11, 375,189, $ color );
Imagestring ($ IMG, 1,361, $ h11-10, $ hour [11], $ color );
Imagestring ($ IMG, 1,364,195, 11, $ BC );
// 12 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 391, $ H12, 405,189, $ color );
Imagestring ($ IMG, 1,391, $ h12-10, $ hour [12], $ color );
Imagestring ($ IMG, 1,394,195, 12, $ BC );
// 13 O'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 421, $ H13, 435,189, $ color );
Imagestring ($ IMG, 1,421, $ h13-10, $ hour [13], $ color );
Imagestring ($ IMG, 1,424,195, 13, $ BC );
// 14 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 451, $ H14, 465,189, $ color );
Imagestring ($ IMG, 1,451, $ h14-10, $ hour [14], $ color );
Imagestring ($ IMG, 1,454,195, 14, $ BC );
// 15 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 481, $ H15, 495,189, $ color );
Imagestring ($ IMG, 1,481, $ h15-10, $ hour [15], $ color );
Imagestring ($ IMG, 1,481,195, 15, $ BC );
// 16 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 511, $ H16, 525,189, $ color );
Imagestring ($ IMG, 1,511, $ h16-10, $ hour [16], $ color );
Imagestring ($ IMG, 1,511,195, 16, $ BC );
// 17 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 541, $ H17, 555,189, $ color );
Imagestring ($ IMG, 1,541, $ h17-10, $ hour [17], $ color );
Imagestring ($ IMG, 1,544,195, 17, $ BC );
// 18 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 571, $ H18, 585,189, $ color );
Imagestring ($ IMG, 1,571, $ h18-10, $ hour [18], $ color );
Imagestring ($ IMG, 1,571,195, 18, $ BC );
// 19 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 601, $ H19, 615,189, $ color );
Imagestring ($ IMG, 1,601, $ h19-10, $ hour [19], $ color );
Imagestring ($ IMG, 1,604,195, 19, $ BC );
// 20 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 631, $ H20, 645,189, $ color );
Imagestring ($ IMG, 1,631, $ h20-10, $ hour [20], $ color );
Imagestring ($ IMG, 1,634,195, 20, $ BC );
// 21: 00
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 661, $ h21, 675,189, $ color );
Imagestring ($ IMG, 1,661, $ h21-10, $ hour [21], $ color );
Imagestring ($ IMG, 1,664,195, 21, $ BC );
//
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 691, $ h22. 705,189, $ color );
Imagestring ($ IMG, 1,691, $ h22-10, $ hour [22], $ color );
Imagestring ($ IMG, 1,694,195, 22, $ BC );
// 23 o'clock
$ Color = imagecolorallocate ($ IMG, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagefilledrectangle ($ IMG, 721, $ H23, 735,189, $ color );
Imagestring ($ IMG, 1,721, $ h23-10, $ hour [23], $ color );
Imagestring ($ IMG, 1,724,195, 23, $ BC );
// It is hard to see if a border is added
// Imagerectangle ($ IMG, 0, 0,754,209, $ BC );
Imagepng ($ IMG );
Imagedestroy ($ IMG );
}
$ STR = isset ($ _ Get ['str'])? $ _ Get ['str']: "";
If ($ Str ){
H24 ($ Str );
}
?>