If the manager sees that I have to be angry with others during work hours
Recently, I have worked hard with GD2, and I like to use it to draw pictures ~~
In fact, histogram is used to calculate coordinates, which is nothing more difficult.
I am stupid and think that, like X and Y, the values below are small. The above big results show that my head is broken, pictures, and screens are all at the top left corner of the origin.
This is the figure I made. It's a little rubbish. Hey hey, I don't have the aesthetic feeling, or I will go to the artist...
Below is Code :
// The statistical analysis Number shown in the figure. Currently, only up to five groups of data can be analyzed (in actual use, the percentage can be calculated)
$ Values = array (100,300,120, 77,230 );
Header ("Content-Type: image/GIF ");
$ Im = imagecreate (400,400 );
// Color
$ White = imagecolorallocate ($ im, 250,250,250 );
$ Black = imagecolorallocate ($ im, 0, 0 );
$ Gray = imagecolorallocate ($ im, 150,150,150 );
$ Blue = imagecolorallocate (USD im, 184,212,250 );
$ Red = imagecolorallocate ($ im, 255, 0, 0 );
// Origin Coordinate
$ Min = array (50,350 );
// Maximum coordinate
$ Max = array (350,50 );
// The interval of the column
$ Space = 20;
// The width of the column
$ Weith = 30;
Imagerectangle ($ im, $ Min [0], $ Min [1], $ MAX [0], $ MAX [1], $ gray );
// Draw a grid line and write the corresponding value on the left
For ($ I = 1; $ I <10; $ I + = 1 ){
$ Y = $ I * 30;
Imagestring ($ im, 5, $ Min [0]-35, $ Min [1]-$ y, $ y, $ black );
Imageline ($ im, $ Min [0] + $ y, $ Min [1], $ Min [0] + $ y, $ MAX [1], $ gray );
Imageline ($ im, $ Min [0], $ MAX [1] + $ y, $ MAX [0], $ MAX [1] + $ y, $ gray );
}
Imagestring ($ im, 5, $ Min [0]-35, $ Min [1]-$ y-30, $ Y + 30, $ black );
// Draw a histogram based on numbers
For ($ I = 0; $ I <5; $ I ++ ){
$ Y = 10 + $ I * 60;
Imagefilledrectangle ($ im, ($ Min [0] + $ space), ($ Min [1]-$ values [$ I]), ($ Min [0] + $ weith + $ space + 7), $ Min [1]-1, $ gray );
Imagefilledrectangle ($ im, ($ Min [0] + $ space), ($ Min [1]-$ values [$ I] + 1 ), ($ Min [0] + $ weith + $ space), $ Min [1]-1, $ blue );
Imagestring ($ im, 5, $ Min [0] + $ y, $ Min [1] + 10, "200". $ I. "Y", $ red );
$ Space = $ space + $ weith + 30;
}
Imagepng ($ IM );
Imagedestroy ($ IM );