Use the GD image library to create a line chart

Source: Internet
Author: User
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 ){

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.