php // map class
Class imageReport {
VAR $ x; // Picture size X-axis
Var $ y; // Picture Size Y axis
Var $ r; // Back color R value
Var $ g; // ... g.
Var $ b; // ... b.
Var $ transparent; // Is transparent 1 or 0
VAR $ image; // picture object
// -------------------
Var $ arraysplit; / / Specify symbols for separating values
Var $ itemRay; // value
Var $ reporttype; // chart type, 1 is vertical column 2 is horizontal 3 is a fold line
Var $ border; // Distance
// -------------------
Var $ fontsize; // font size
Var $ fontcolor; // font color
VAR $ Numx = 1; // X axis starting magnetic value
VAR $ stepx = 1; // X axis Each scale interval value
// -------- 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-> itemray = $ itmarray;
$ this-> reporttype = $ reporttype;
$ this-> border = $ boorder;
}
Function SetFont ($ fontsize) {
$ this-> fontsize = $ fontsize;
}
// x-axis flap setting
Function SetX ($ Numx = 1, $ Stepx = 1) {
$ this-> Numx = $ NUMX;
$ this-> stepx = $ stepx;
}
//----------------main body
Function printReport () {
// Establish a canvas size
$ this-> image = imagecreate ($ this-> x, $ this-> y);
// Set the color of the canvas background
$ background = ImageColoralLocate ($ this-> Image, $ this-> r, $ this-> g, $ this-> b);
IF ($ this-> Transparent == "1") {
// Back shades
ImageColorTransparent ($ this-> image, $ background);
} else {
// If you don't transparency, you can fill the background color.
ImageFilledRectangle ($ this-> Image, 0,0, $ this-> x, $ this-> y, $ background;
}
// paragraph text body small 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 ();
Case "3":
$ this-> imageline ();
Break;
Case "4":
$ this-> imagecircle ();
Break;
}
$ this-> printxy ();
$ this-> printall ();
}
/ / ----------- Print XY Cart Shaft
Function printxy () {
$ rulery = $ rulerx = "";
// Draw XY Card Barrier * /
$ color = imagecoloralloccate ($ this-> image, 255- $ this-> r, 255- $ this-> g, 255- $ this-> b);
$ xx = $ tris-> x / 10;
$ yy = $ this-> y- $ this-> y / 10;
ImageLine ($ this-> Image, $ this-> Border, $ this-> border, $ 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
ImagesTring ($ this-> Image, $ this-> Fontsize, $ this-> Border-2, $ this-> y- $ this-> border 5, "0", $ color);
// Y-axis scale
$ Rulery = $ this-> y- $ this-> border;
$ I = 0;
While ($ Rulery> $ this-> border * 2) {
$ Rulery = $ Rulery- $ this-> border;
Images-> Image, $ this-> Border, $ Rulery, $ this-> border-2, $ rulery, $ color);
IF ($ this-> reporttype == 2) {// horizontal map
Images-> Fontsize, $ THIS-> Border-10, $ Rulery-2- $ THIS-> Border * ($ I .5), $ THIS-> Numx, $ Color;
$ this-> Numx = $ this-> stepx;
}
$ i ;
}
// x axis scale
$ rulerx = $ rulerx $ this-> border;
$ I = 0;
While ($ RULERX <($ THIS-> X- $ THIS-> Border * 2)) {
$ rulerx = $ rulerx $ this-> border;
// Imageline ($ this-> Image, $ this-> border, 10, $ this-> border 10, 10, $ color);
Imageline ($ THIS-> Image, $ RULERX, $ THIS-> Y- $ THIS-> Border, $ RULERX, $ THIS-> Y- $ THIS-> Border 2, $ Color;
/ / Scale value
IF ($ this-> reporttype == 1) {// vertical column
ImageString ($ this-> Image, $ this-> Fontsize, $ RULERX-2 $ THIS-> Border * ($ I .5), $ this-> Y- $ THIS-> Border 5, $ this-> Numx, $ color); $ this-> Numx = $ this-> stepx;
Else IF ($ this-> reporttype == 3) {// Pacing chart
ImageString ($ this-> Image, $ this-> Fontsize, $ RULERX-2, $ THIS-> Y- $ THIS-> Border 5, $ this-> Numx, $ Color;
$ this-> Numx = $ this-> stepx;
}
$ i ;
}
}
/ / ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function imagecolumns () {
$ item_ARRAY = Split ($ this-> arraysplit, $ this-> itmarray);
$ Num = Count ($ Item_Array);
$ item_max = 0;
For ($ I = 0; $ I <$ NUM; $ I ) {
$ item_MAX = Max ($ Item_MAX, $ Item_Array [$ I]);
}
$ xx = $ this-> border * 2;
// Paste column
For ($ I = 0; $ I <$ NUM; $ I ) {
SRAND (Double) microtime () * 1000000);
IF ($ THIS-> R! = 255 && $ this-> g! = 255 && $ this-> b! = 255) {
$ R = rand ($ this-> r, 200);
$ G = rand ($ THIS-> G, 200);
$ B = rand ($ THIS-> B, 200);
} else {
$ R = Rand (50, 200);
$ G = rand (50, 200);
$ B = rand (50, 200);
}
$ color = imagecolorlocate ($ this-> Image, $ R, $ G, $ B);
// Cylindrical height
$ HEIGHT = ($ THIS-> Y- $ THIS-> Border) - ($ this-> Y- $ this-> border * 2) * ($ Item_Array [$ I] / $ Item_max);
ImageFilledRectangle ($ THIS-> Image, $ XX, $ HEIGHT, $ XX $ THIS-> Border, $ this-> Y- $ this-> border, $ color);
Images -> Fontsize, $ XX, $ Height- $ this-> Border, $ Item_Array [$ I], $ THIS-> FontColor;
// Used for interval
$ xx = $ × $ this-> border * 2;
}
}
// ----------- Cross-column
Function imagecolumnh () {
$ item_ARRAY = Split ($ this-> arraysplit, $ this-> itmarray);
$ Num = Count ($ Item_Array);
$ item_max = 0;
For ($ I = 0; $ I <$ NUM; $ I ) {
$ item_max = max ($ Item_MAX, $ Item_Array [$ I]);
$ yy = $ this-> y- $ this-> border * 2;
// Paste column
For ($ I = 0; $ I <$ NUM; $ I ) {
SRAND (Double) microtime () * 1000000);
IF ($ THIS-> R! = 255 && $ this-> g! = 255 && $ this-> b! = 255) {
$ R = rand ($ this-> r, 200);
$ G = rand ($ THIS-> G, 200);
$ B = rand ($ THIS-> B, 200);
} else {
$ R = Rand (50, 200);
$ G = rand (50, 200);
$ B = rand (50, 200);
}
$ color = imagecolorlocate ($ this-> Image, $ R, $ G, $ B);
// Cylindrical length
$ Leight = ($ this-> x- $ this-> border * 2) * ($ Item_Array [$ I] / $ Item_max);
$ Leight = $ Leight <$ this-> border? $ this-> border: $ leight;
ImageFilledRectangle ($ this-> Image, $ this-> Border, $ YY- $ THIS-> Border, $ Leight, $ yy, $ color);
Images -> Fontsize, $ Leight 2, $ YY- $ THIS-> Border, $ Item_Array [$ I], $ this-> fontcolor;
// Used for interval
$ yy = $ yy- $ this-> border * 2;
}
}
//--------------line chart
Function imageline () {
$ item_ARRAY = Split ($ this-> arraysplit, $ this-> itmarray);
$ Num = Count ($ Item_Array);
$ item_max = 0;
For ($ I = 0; $ I <$ NUM; $ I ) {
$ item_MAX = Max ($ Item_MAX, $ Item_Array [$ I]);
}
$ xx = $ this-> border;
// Paste column
For ($ I = 0; $ I <$ NUM; $ I ) {
SRAND (Double) microtime () * 1000000);
IF ($ THIS-> R! = 255 && $ this-> g! = 255 && $ this-> b! = 255) {
$ R = rand ($ this-> r, 200);
$ G = rand ($ THIS-> G, 200);
$ B = rand ($ THIS-> B, 200);
} else {
$ R = Rand (50, 200);
$ G = rand (50, 200);
$ B = rand (50, 200);
}
$ color = imagecolorlocate ($ this-> Image, $ R, $ G, $ B);
// Cylindrical height
$ HEIGHT_NOW = ($ THIS-> Y- $ THIS-> Border) - ($ this-> y- $ this-> border * 2) * ($ Item_Array [$ I] / $ Item_max);
IF ($ I! = "0")
Imageline ($ THIS-> Image, $ XX- $ THIS-> Border, $ HEIGHT_NEXT, $ XX, $ HEIGHT_NOW, $ Color; ImageString ($ this-> Image, $ this-> Fontsize, $ XX 2, $ HEIGHT_NOW- $ THIS-> Border / 2, $ Item_Array [$ I], $ this-> fontcolor;
$ height_next = $ height_now;
// Used for interval
$ xx = $ xx $ tris-> border;
}
}
//--------------pie chart
Function imagecircle () {
$ TOTAL = 0;
$ item_ARRAY = Split ($ this-> arraysplit, $ this-> itmarray);
$ Num = Count ($ Item_Array);
$ item_max = 0;
For ($ I = 0; $ I <$ NUM; $ I ) {
$ item_MAX = Max ($ Item_MAX, $ Item_Array [$ I]);
$ TOTAL = $ ITEM_Array [$ I];
}
$ yy = $ this-> y- $ this-> border * 2;
// Shadow part of the painting chart
$ E = 0;
For ($ I = 0; $ I <$ NUM; $ I ) {
SRAND (Double) microtime () * 1000000);
IF ($ THIS-> R! = 255 && $ this-> g! = 255 && $ this-> b! = 255) {
$ R = rand ($ this-> r, 200);
$ G = rand ($ THIS-> G, 200);
$ B = rand ($ THIS-> B, 200);
} else {
$ R = Rand (50, 200);
$ G = rand (50, 200);
$ B = rand (50, 200);
}
$ S = $ E;
$ Leight = $ Item_Array [$ I] / $ TOTAL * 360;
$ E = $ S $ Leight;
$ color = imagecolorlocate ($ this-> Image, $ R, $ G, $ B);
$ Colorarray [$ I] = $ color;
// Painting round
For ($ J = 90; $ J> 70; $ J - Imagefilledarc ($ THIS-> Image, 110, $ J, 200, 100, $ S, $ E, $ Color, IMG_ARC_PIE);
// Imagefilledarc ($ this-> Image, 110, 70, 200, 100, $ s, $ e, $ color, img_arc_pie);
// ImagefilledRectangle ($ this-> Image, $ this-> Border, $ YY- $ THIS-> Border, $ Leight, $ YY, $ color);
// Imagestring ($ this-> Image, $ this-> Fontsize, $ Leight 2, $ YY- $ THIS-> Border, $ Item_Array [$ I], $ THIS-> FontColor);
// Used for interval
$ yy = $ yy- $ this-> border * 2;
}
// Surface part of the painting chart
$ E = 0;
For ($ I = 0; $ I <$ NUM; $ I ) {
SRAND (Double) microtime () * 1000000);
IF ($ this-> r! = 255 && $ this-> g! = 255 && $ this-> b! = 255) {$ r = rand ($ this-> r, 200);
$ G = rand ($ THIS-> G, 200);
$ B = rand ($ THIS-> B, 200);
} else {
$ R = Rand (50, 200);
$ G = rand (50, 200);
$ B = rand (50, 200);
}
$ S = $ E;
$ Leight = $ Item_Array [$ I] / $ TOTAL * 360;
$ E = $ S $ Leight;
// $ color = $ colorarray [$ I];
$ color = imagecolorlocate ($ this-> Image, $ R, $ G, $ B);
// Painting round
// for ($ J = 90; $ J> 70; $ J - Imagefilledarc ($ this-> Image, 110, $ j, 200, 100, $ s, $ e, $ color, img_arc_pie);
Imagefilledarc ($ THIS-> Image, 110, 70, 200, 100, $ s, $ e, $ color, img_arc_pie;
}
}
// -------------- Complete print graphics
Function printall () {
ImagePNG ($ this-> image);
ImageDestroy ($ this-> image);
}
//--------------debugging
Function debug () {
Echo "x:". $ this-> x. "y:". $ this-> y;
Echo "Border:". $ this-> border;
$ item_ARRAY = Split ($ this-> arraysplit, $ this-> itmarray);
$ Num = Count ($ Item_Array);
Echo "Number of Number:". $ Num. "Numerical:";
For ($ I = 0; $ I <$ NUM; $ I ) {
Echo "" "$ item_Array [$ I];
}
}
}
// $ report-> debug (); // Elementary
/ *
Header ("Content-Type: Image / PNG");
$ report = new imageReport;
$ report-> setimage (600, 500, 255, 255, 255, 1); // parameter (length, high, back color R, g, b, is transparent 1 or 0)
$ TEMPARRAY = "0, 260, 400, 124, 48, 720, 122, 440, 475"; // Value, separated by specified symbol
$ report-> setItem (',', $ TEMPARRAY, 3, 23); // Parameter (Separate value specified symbol, numerical variable, style 1 is a vertical column Figure 2 is the horizontal pillar Figure 3 is a fold line diagram 4 ,distance)
$ report-> setfont (1); // font size 1-10
// $ report-> setx (1, 1); // Set the X-axis scale value (the starting scale value = 1, the scale interval = 1)
$ report-> printReport ();
* /
?>