Recently, a GD library is used to create a class library for both horizontal and vertical column charts and line charts. it is a teaching routine. ClassImageReport {var $ X; // Image Size X axis var $ Y; // image size Y axis var $ R; // background color R value var $ G ;//... g. var $ B ;//... b. var $ TRANSPAR
A recently written GD Library is a class library that is designed for both horizontal and vertical column charts and line charts. it is a teaching routine.
Class ImageReport {
Var $ X; // Image Size X axis
Var $ Y; // the Y axis of the image size.
Var $ R; // R value of the background color
Var $ G; //... G.
Var $ B; //... B.
Var $ TRANSPARENT; // whether TRANSPARENT 1 or 0
Var $ IMAGE; // IMAGE
//-------------------
Var $ ARRAYSPLIT; // specifies the symbol used to separate numeric values.
Var $ ITEMARRAY; // value
Var $ REPORTTYPE; // Chart type. 1 is a vertical column, 2 is a horizontal column, and 3 is a line.
Var $ BORDER; // interval
//-------------------
Var $ FONTSIZE; // font size
Var $ FONTCOLOR; // font color
// -------- Parameter setting function
Function setImage ($ SizeX, $ SizeY, $ R, $ G, $ B, $ Transparent ){
$ This-> X = $ SizeX;
$ This-> Y = $ SizeY;
$ This-> R = $ R;
$ This-> G = $ G;
$ This-> B = $ B;
$ This-> TRANSPARENT = $ Transparent;
}
Function setItem ($ ArraySplit, $ ItemArray, $ ReportType, $ Border ){
$ This-> ARRAYSPLIT = $ ArraySplit;
$ This-> ITEMARRAY = $ ItemArray;
$ This-> REPORTTYPE = $ ReportType;
$ This-> BORDER = $ Border;
}
Function setFont ($ FontSize ){
$ This-> FONTSIZE = $ FontSize;
}
// ---------------- Subject
Function PrintReport (){
Header ('content-type: image/gif ');
// Create the canvas size
$ This-> IMAGE = ImageCreate ($ this-> X, $ this-> Y );
// Set the landscape on the back of the canvas
$ Background = ImageColorAllocate ($ this-> IMAGE, $ this-> R, $ this-> G, $ this-> B );
If ($ this-> TRANSPARENT = '1 '){
// Transparent Background
Imagecolortransparent ($ this-> IMAGE, $ background );
} Else {
// If not transparent, you can fill in the back Landscape
ImageFilledRectangle ($ this-> IMAGE, 0, 0, $ this-> X, $ this-> Y, $ background );
}
// Small body text and color
$ This-> FONTCOLOR = ImageColorAllocate ($ this-> IMAGE, 255-$ this-> R, 255-$ this-> G, 255-$ this-> B );
Switch ($ this-> REPORTTYPE ){
Case '0 ':
Break;
Case '1 ':
$ This-> imageColumnS ();
Break;
Case '2 ':
$ This-> imageColumnH ();
Break;
Case '3 ':
$ This-> imageLine ();
Break;
}
$ This-> printXY ();
$ This-> printAll ();
}
// ----------- Print the XY axis
Function printXY (){
// Draw the XY axis */
$ Color = ImageColorAllocate ($ this-> IMAGE, 255-$ this-> R, 255-$ this-> G, 255-$ this-> B );
$ Xx = $ this-> X/10;
$ Yy = $ this-> Y-$ this-> Y/10;
ImageLine ($ this-> IMAGE, $ this-> BORDER, $ this-> Y-$ this-> BORDER, $ color); // x axis
ImageLine ($ this-> IMAGE, $ this-> BORDER, $ this-> Y-$ this-> BORDER, $ this-> X-$ this-> BORDER, $ this-> Y-$ this-> BORDER, $ color); // Y axis
// Scale up on the y axis
$ RulerY = $ this-> Y-$ this-> BORDER;
While ($ rulerY> $ this-> BORDER * 2 ){