There was nothing in the afternoon, so we made a numerical statistics histogram. It was fun.

Source: Internet
Author: User

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 );

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.