- 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; // Distance
- //-------------------
- Var $ FONTSIZE; // font size
- Var $ FONTCOLOR; // font color
-
- Var $ numX = 1; // Start scale value of the X axis
- Var $ stepX = 1; // The interval between each scale on the x axis
-
- // -------- 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;
- }
- // Set the x axis scale value
- Function setX ($ numX = 1, $ stepX = 1 ){
- $ This-> numX = $ numX;
- $ This-> stepX = $ stepX;
- }
- // ---------------- Subject
- Function PrintReport (){
- // Create the canvas size
- $ This-> IMAGE = ImageCreate ($ this-> X, $ this-> Y );
- // Set the canvas background color
- $ Background = ImageColorAllocate ($ this-> IMAGE, $ this-> R, $ this-> G, $ this-> B );
- If ($ this-> TRANSPARENT = "1 "){
- // Transparent Background
- Imagecolortransparent ($ this-> IMAGE, $ background );
- } Else {
- // The background color can be filled if it is not transparent.
- ImageFilledRectangle ($ this-> IMAGE, 0, 0, $ this-> X, $ this-> Y, $ background );
- }
- // Small integer 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;
- Case "4 ":
- $ This-> imageCircle ();
- Break;
- }
- $ This-> printXY ();
- $ This-> printAll ();
- }
- // ----------- Print the XY axis
- Function printXY (){
- $ RulerY = $ rulerX = "";
- // 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
- Imagestring ($ this-> IMAGE, $ this-> FONTSIZE, $ this-> BORDER-2, $ this-> Y-$ this-> BORDER + 5, "0 ", $ color );
- // Scale up on the y axis
- $ RulerY = $ this-> Y-$ this-> BORDER;
- $ I = 0;
- While ($ rulerY> $ this-> BORDER * 2 ){
- $ RulerY = $ rulerY-$ this-> BORDER;
- ImageLine ($ this-> IMAGE, $ this-> BORDER, $ rulerY, $ this-> BORDER-2, $ rulerY, $ color );
-
- If ($ this-> REPORTTYPE = 2) {// horizontal bar chart
- Imagestring ($ this-> IMAGE, $ this-> FONTSIZE, $ this-> BORDER-10, $ rulerY-2-$ this-> BORDER * ($ I +. 5), $ this-> numX, $ color );
- $ This-> numX + = $ this-> stepX;
- }
- $ I ++;
- }
- // Scale up on the x axis
- $ 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 bar chart
- 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) {// Line chart
- Imagestring ($ this-> IMAGE, $ this-> FONTSIZE, $ rulerX-2, $ this-> Y-$ this-> BORDER + 5, $ this-> numX, $ color );
- $ This-> numX + = $ this-> stepX;
- }
- $ I ++;
- }
- }
-
- // -------------- Vertical bar chart
- Function imageColumnS (){
- $ Item_array = Split ($ this-> ARRAYSPLIT, $ this-> ITEMARRAY );
- $ 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;
- // Draw a column chart
- 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 = revert (50,200 );
- $ G = revert (50,200 );
- $ B = revert (50,200 );
- }
- $ Color = ImageColorAllocate ($ this-> IMAGE, $ R, $ G, $ B );
- // Column 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 );
- ImageString ($ this-> IMAGE, $ this-> FONTSIZE, $ xx, $ height-$ this-> BORDER, $ item_array [$ I], $ this-> FONTCOLOR );
- // Used for interval
- $ Xx = $ xx + $ this-> BORDER * 2;
- }
- }
- // ----------- Horizontal column chart
- Function imageColumnH (){
- $ Item_array = Split ($ this-> ARRAYSPLIT, $ this-> ITEMARRAY );
- $ 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;
- // Draw a column chart
- 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 = revert (50,200 );
- $ G = revert (50,200 );
- $ B = revert (50,200 );
- }
- $ Color = ImageColorAllocate ($ this-> IMAGE, $ R, $ G, $ B );
- // Column 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 );
- ImageString ($ this-> IMAGE, $ this-> 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-> ITEMARRAY );
- $ Num = Count ($ item_array );
- $ Item_max = 0;
- For ($ I = 0; $ I <$ num; $ I ++ ){
- $ Item_max = Max ($ item_max, $ item_array [$ I]);
- }
- $ Xx = $ this-> BORDER;
- // Draw a column chart
- 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 = revert (50,200 );
- $ G = revert (50,200 );
- $ B = revert (50,200 );
- }
- $ Color = ImageColorAllocate ($ this-> IMAGE, $ R, $ G, $ B );
- // Column 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 + $ this-> BORDER;
- }
- }
- // -------------- Pie chart
- Function imageCircle (){
- $ Total = 0;
- $ Item_array = Split ($ this-> ARRAYSPLIT, $ this-> ITEMARRAY );
- $ 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;
-
- // Draw the shadow part of the pie 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 = revert (50,200 );
- $ G = revert (50,200 );
- $ B = revert (50,200 );
- }
- $ S = $ e;
- $ Leight = $ item_array [$ I]/$ total * 360;
- $ E = $ s + $ leight;
- $ Color = ImageColorAllocate ($ this-> IMAGE, $ R, $ G, $ B );
- $ Colorarray [$ I] = $ color;
- // Circle
- 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;
- }
-
- // Draw the surface of the pie 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 = revert (50,200 );
- $ G = revert (50,200 );
- $ B = revert (50,200 );
- }
- $ S = $ e;
- $ Leight = $ item_array [$ I]/$ total * 360;
- $ E = $ s + $ leight;
- // $ Color = $ colorarray [$ I];
- $ Color = ImageColorAllocate ($ this-> IMAGE, $ R, $ G, $ B );
- // Circle
- // 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 );
- }
- }
- // -------------- Print the image
- Function printAll (){
- ImagePNG ($ this-> IMAGE );
- ImageDestroy ($ this-> IMAGE );
- }
- // -------------- Debug
- Function debug (){
- Echo "X:". $ this-> X ."
Y: ". $ this-> Y;
- Echo"
BORDER: ". $ this-> BORDER;
- $ Item_array = split ($ this-> ARRAYSPLIT, $ this-> ITEMARRAY );
- $ Num = Count ($ item_array );
- Echo"
Number of values: ". $ num ." Value :";
- For ($ I = 0; $ I <$ num; $ I ++ ){
- Echo"
". $ Item_array [$ I];
- }
- }
- }
- // $ Report-> debug (); // call for debugging
- /*
- Header ("Content-type: image/png ");
- $ Report = new ImageReport;
- $ Report-> setImage (600,500,255,255,255, 1); // parameter (long, high, back color R, G, B, whether transparent 1 or 0)
- $ Temparray = "0,260,400,124, 48,720,122,440,475"; // value, separated by a specified symbol
- $ Report-> setItem (',', $ temparray, 3, 23); // parameters (specify the separator between values, numerical variables, style 1 is a vertical column, a horizontal column, a broken line, a pie chart, and a distance)
- $ Report-> setFont (1); // font size: 1-10
- // $ Report-> setX (); // Set the x axis scale value (start scale value = 1, scale interval value = 1)
- $ Report-> PrintReport ();
- */
- ?>
|