Jpgraph generates type data in the form of charts and trend charts.

Source: Internet
Author: User
Tags php tutorial
The code is as follows: Copy code

<? Php Tutorial

/**
* Ecshop jpgraph chart class library
* ===================================================== ======================================
* The open-source jpgraph library is used to display various types of data in charts and trend charts.
* ===================================================== ======================================
**/

Class cls_jpgraph
{
Var $ db = null;
Var $ ydata = array ();
Var $ width = 350;
Var $ height = 250;

Var $ graph = ''; // graphic object
Var $ piegraph = ''; // C-shaped image

Var $ lineplot = ''; // linear object
Var $ barpot = ''; // columnar object
Var $ gbplat = ''; // Column Group object
Var $ txt = ''; // text object
Var $ p1 = ''; // A Graph object

Var $ scale = ''; // Chart type? (Textlin, textlog, intlin)
Var $ yscale = ''; // (log ,)
Var $ xgrid = false; // x axis grid display
Var $ ygrid = false; // Y axis grid display
Var $ title = ''; // title
Var $ subtitle = ''; // subtitle (generally a date)
Var $ xaxis = ''; // x axis name
Var $ yaxis = ''; // Y axis name

/* Margin position */
Var $ left = 0;
Var $ right = 0;
Var $ top = 0;
Var $ bottom = 0;

/**
* Constructor
*/
Function cls_jpgraph ($ width = 350, $ height = 250)
 {
$ This-> width = $ width;
$ This-> height = $ height;

$ This-> graph = new graph ($ this-> width, $ this-> height );

 }

/**
* Constructor of the chart class library
 *
*/
/*
Function _ construct ($ parms, $ width, $ height)
 {
Cls_jpgraph ($ parms, $ width, $ height );
 }
*/

/* Set basic image information */
Function set_jpgraph ($ scale = 'intlin', $ title = '', $ subtitle ='', $ bgcolor = '', $ xaxis = '',
$ Yaxis = '', $ xgrid = false, $ ygrid = false, $ margin = ''){

$ This-> scale = $ scale;
$ This-> title = $ title;
$ This-> subtitle = $ subtitle;
$ This-> xaxis = $ xaxis;
$ This-> yaxis = $ yaxis;
$ This-> xgrid = $ xgrid;
$ This-> ygrid = $ ygrid;

If (! Empty ($ scale )){
$ This-> graph-> setscale ($ this-> scale );
  }
Else {
$ This-> graph-> setscale ('intlin ');
  }
$ This-> graph-> xgrid-> show ($ this-> xgrid, $ this-> xgrid );
$ This-> graph-> ygrid-> show ($ this-> ygrid, $ this-> ygrid );

If (! Empty ($ bgcolor )){
$ This-> graph-> setmargincolor ($ bgcolor );
  }

/* If you manually set the image position */
If (is_array ($ margin )){
While (list ($ key, $ val) = each ($ margin )){
$ This-> $ key = $ val;
   }
$ This-> graph-> setmargin ($ this-> left, $ this-> right, $ this-> top, $ this-> bottom );
  }

If (! Empty ($ this-> title )){
$ This-> graph-> title-> set ($ this-> title );
  }
If (! Empty ($ this-> subtitle )){
$ This-> graph-> subtitle-> set ($ this-> subtitle );
  }
Else {
$ This-> graph-> subtitle-> set ('('. date ('Y-m-D '). '); // The default subtitle is set to the current date.
  }
If (! Empty ($ this-> xaxis )){
$ This-> graph-> xaxis-> title-> set ($ this-> xaxis );
  }
If (! Empty ($ this-> yaxis )){
$ This-> graph-> yaxis-> title-> set ($ this-> yaxis );
  }

 }

/* Create a linear relationship chart (linear plot )*/
Function create_lineplot ($ parms, $ color = 'black', $ weight = 1)
 {
$ This-> ydata = $ parms;
$ This-> lineplot = new lineplot ($ this-> ydata );
$ This-> lineplot-> setcolor ($ color );
$ This-> lineplot-> setweight ($ weight );

Return $ this-> lineplot;
 }

/* Create bar pot )*/
Function create_barpot ($ parms, $ color = 'black', $ width = '0 ')
 {
$ This-> ydata = $ parms;
$ This-> barpot = new barplot ($ this-> ydata );
$ This-> barpot-> setfillcolor ($ color );
If (! Empty ($ width )){
$ This-> barpot-> setwidth ($ width );
  }

Return $ this-> barpot;
 }

/* Create a data columnar chart Group */
Function create_bargroup ($ plotarr, $ width = '0. 8 ')
 {
$ This-> gbplot = new groupbarplot ($ plotarr );
$ This-> gbplot-> setwidth ($ width );

Return $ this-> gbplot;
 }

/* Create text content */
Function create_text ($ str, $ postion = '', $ color = 'black ')
 {
$ This-> txt = new text ($ str );

If (is_array ($ postion )){
While (list ($ key, $ val) = each ($ postion )){
$ This-> $ key = $ val;
   }
$ This-> txt-> setpos ($ this-> left, $ this-> top );
  }
Else {
$ This-> txt-> setpos (10, 20 );
  }
$ This-> txt-> setcolor ($ color );

$ This-> graph-> add ($ this-> txt );
 }

/* Create a C-type chart */
Function create_pie ($ parms, $ title, $ type = '3D ', $ size = '0. 5', $ center = '0. 5', $ width = '000000', $ height = '000000 ')
 {
$ This-> width = $ width;
$ This-> height = $ height;

$ This-> piegraph = new piegraph (300,200 );
$ This-> piegraph-> setshadow ();

$ This-> piegraph-> title-> set ($ title );

If ('3D '! = $ Type ){
$ This-> p1 = new pieplot ($ parms );
$ This-> piegraph-> add ($ this-> p1 );
  }
Else {
$ This-> p1 = new pieplot3d ($ parms );
$ This-> p1-> setsize ($ size );
$ This-> p1-> setcenter ($ center );
// $ This-> p1-> setlegends ($ gdatelocale-> get1_month ());
$ This-> piegraph-> add ($ this-> p1 );
  }
$ This-> piegraph-> stroke ();
 }

Function get_auth_code ($ length = 4)
 {
$ Spam = new antispam ();
$ Chars = $ spam-> rand ($ length );

If ($ spam-> stroke () === false ){
Return false;
  }

Return $ chars;
 }

/* Create and display the image */
Function display ($ obj)
 {
$ This-> graph-> add ($ obj );
$ This-> graph-> stroke ();
 }
}

?>

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.