$ b = array (150, 110, 125, 180, 160, 175, 230, 220);?> Is a set of data, where is the data, is no
If you turn off, you will look at your needs; I need to say two words in the code. I have added a comment, and now explain it.
(1) It should be noted here that valign = "bottom" is to align the content of the cell's content. Why add in
? You can let the contents of this line in the form, you don't have to specify in each
, so
To save dozens of bytes to the original code of the HTML page of the PHP execution result! Saving the valuable time of the viewer.
(2) Note that the most critical thing is here!
, we use the Table's Height property.
Realize the "column" of different heights. I will see you clearly, the original data has not been scaled.
If your data is particularly large, or it is particularly small, it is not appropriate to directly assign it directly to the height property, but should
The status is scaled according to the appropriate proportion. For example, you estimate that every number of this data will be between 3000 and 8000,
It can be considered to shrink them 25 times, ie Height = " Echo floor (b [$ I] / 25);?>" (3) Let's take the bgcolor = "# xxxxxx" in this line, this is the column Color (RGB). In fact, the real histogram should be
Every column is used in a color, here is simple as possible, I use this for loop, so there is no way to give
Each cylinder specifies a color. - In fact, there is also a way. I just don't have to write again for this example.
A function of extracting color is dizzy. So, that part is perfect by yourself.
(4) Display real data herein with the same color as the column. Of course, you can also choose to put this figure on the top of the column.
On, it may be more professional. However, I am still accustomed to putting it below.
With HTML Table, we can construct various histograms, this example is to use BGColor to display the color block.
In addition, it is also possible to use a background = "(picture)", the picture is a pattern, so the column of the histogram has a pattern.
And you put the real data with a large color, the
shown in the
shown above (3), is also a good effect.
The front is an effective way to avoid GD, but to do a complex graphic, it is not available in GD.
Sadly's PHP4 Chinese manual, saying 44 functions in the GD function library, but I look at the latest version of the English php4 manual,
There are more than 80 functions of GD! Because the author is relatively poor, read English manuals can only cover it, so it cannot be sure
Does the new GD library re-support GIF? Anyway, I think that since we are using a completely free PHP, why
"Adventure" to use the copyright-owned GIF? Why not free, use PNG? As long as you don't need to use animation, PNG can also make
As small as a GIF!
Below I will combine a program, a code, a code, talk about commonly used GD functions.
Start from the beginning.
Header ("Content-Type: Image / PNG");
// This is to send an HTTP header, telling the browser: "You listen, this is an image, you can make a text to show it!"
// Due to my personal preferences, I used PNG, of course, you can also use Header ("Content-Type: Image / GIF");
// or Header ("Content-Type: Image / JPEG");
$ IM = ImageCreate (50, 100);
// Create an image. Note that the image is not specified in the image format when it is created.
// ImageCreate function, two parameters, no doubt, this is the width and height of the created image.
// The return value is an int value, this value is quite important, you continue to draw this image,
// until you output this image, there is nowhere to this value, we call the ID of the image.
// Because the frequency used is quite high, we assign it to a variable that is relatively short.
// Now let's draw a line first. The function of the line is like this:
// imageline (int ign, int x1, int y1, int x2, int y2, int co);
/ / The first parameter IM is the ID of the image, the back X1, Y1, X2, Y2, no need to say, // is the coordinates of the starting point (X1, Y1) endpoint (x2, y2)! (The upper left corner coordinate of the image is (0,0))
// What is the last parameter? Is color! GD requires a color to define colors for image, and is made with these colors.
// Why define color to image? I guess, for the "palette" for images such as GIF, PNG.
// This involves the knowledge of the image itself, and will not be described here.
// Therefore, before the line, we must first define the color (really trouble).
// $ colalocate ($ IM, 255, 192, 192);
// This function is four parameters, the first $ IM ... still used to say every time? Don't say it next time!
// The three parameters later are the red (R), green (G), blue (B) of the color to be defined, between 0 and 255.
// This is also involved in physical - optical knowledge. Red, green, blue three original color of the original color,
// produce a thousand variable colors. This color, red 255, green 192, blue 192, blue 192.
// If you don't make a mistake, this is a brighter red. Waiting for a while, let's draw a line to try.
// Why wait for a while? Because a picture has only one color, what can't be seen!
// We make the background to black first!
// Although there is no clear expression on the manual, I found the first color to be default the background.
$ colorAllocate ($ IM, 0, 0, 0);
// Define a color, red, green, and blue, natural black, black.
/ / Then define the color of the drawer:
$ colorAllocate ($ IM, 255, 192, 192);
/ / Can now start drawing the red line:
Imageline ($ IM, 10, 20, 45, 85, $ col_red);
// Don't worry, you can't see the image after this sentence.
ImagePNG ($ IM);
// This sentence outputs an image, imagepng () outputs a PNG image, imagejpeg outputs a JPEG image,
// ImageGIF output GIF image ...
/ / Don't forget that there is a parameter, if you are displayed on the screen, not saved as a file,
// omit this parameter - the file name saved. If you want to save it as a file,
// should write this: imagePng ($ IM, "Test.png");
// If you don't specify a path, this file is saved in your web current directory.
// If it is JPEG, then one more parameters is JPEG mass (0 ~ 100).
// If you want to display on the screen, imagejpeg ($ IM, ", 80);
// If you want to save, ImageJpeg ($ IM, "Test.jpg", 80);
// Note, if you want to save this image as a file,
// You can't use Header ("Content-Type: Image / PNG"); transfer means the HTTP header of the image,
// Because of this, you will indicate that you will output an image.
ImageDestroy ($ IM);
// Destroy the image in the memory to release memory space.
// This is fine: a picture of the simplest GD work. // By testing, this image file is generated, only 131 bytes in PNG format,
// and use JPEG format, even with the worst quality (0), it takes 855 bytes, and the image quality is bad.
// The highest JPEG quality requires 2360 bytes, but the color is still not as bright as PNG.
// This shows that the image of such a number of colors is much more cost-effective than JPEG than JPEG.
?>
This time, I will say this, I will strive to continue writing as soon as possible.