Home >Backend Development >PHP Tutorial >jpgraph generates type data and displays it in the form of charts and trend charts_PHP tutorial

jpgraph generates type data and displays it in the form of charts and trend charts_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:45:21971browse

/**
* ecshop jpgraph chart library
* ================================================= =============
* Use the open source jpgraph library to display various types of data in the form of 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 = ''; //Piegraph graph

var $lineplot = ''; //Linear object
var $barpot = ''; //Bar object
var $gbplat = ''; //Column group object
var $txt = ''; //Text object
var $p1 = ''; //Program 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 (usually 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 chart class library
*
​*/
/*
function __construct($parms,$width,$height)
{
cls_jpgraph($parms,$width,$height);
}
*/

/*Basic picture information settings*/
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 the image position is set manually*/
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);
}

}

 /*创建线性关系图表(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;
 }

 /*创建柱状图表(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;
 }

 /*创建数据柱状图表组*/
 function create_bargroup($plotarr,$width='0.8')
 {
  $this->gbplot = new groupbarplot($plotarr);
  $this->gbplot->setwidth($width);

  return $this->gbplot;
 }

 /*创建文本内容*/
 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);
 }

 /*创建丙状图表*/
 function create_pie($parms,$title,$type='3d',$size='0.5',$center='0.5',$width='350',$height='250')
 {
  $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->getshortmonth());
   $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;
 }

 /*完成图形创建并显示*/
 function display($obj)
 {
  $this->graph->add($obj);
  $this->graph->stroke();
 }
}

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/633013.htmlTechArticle?php教程 /** * ecshop jpgraph图表类库 * ============================================================== * 利用开源的jpgraph库实现对各类型数据以图表,走势图的...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn