jpgraph 生成类型数据以图表走势图的形式表现出来 |
时间:2015-01-23 来源:西部数据 作者:西部数据 |
|
- <?php
-
-
-
-
-
-
-
-
- class cls_jpgraph
- {
- var $db = null;
- var $ydata = array();
- var $width = 350;
- var $height = 250;
-
- var $graph = '';
- var $piegraph = '';
-
- var $lineplot = '';
- var $barpot = '';
- var $gbplat = '';
- var $txt = '';
- var $p1 = '';
-
- var $scale = '';
- var $yscale = '';
- var $xgrid = false;
- var $ygrid = false;
- var $title = '';
- var $subtitle = '';
- var $xaxis = '';
- var $yaxis = '';
-
-
- var $left = 0;
- var $right = 0;
- var $top = 0;
- var $bottom = 0;
-
-
-
-
- function cls_jpgraph($width=350,$height=250)
- {
- $this->width = $width;
- $this->height = $height;
-
- $this->graph = new graph($this->width,$this->height);
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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(!emptyempty($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(!emptyempty($bgcolor)) {
- $this->graph->setmargincolor($bgcolor);
- }
-
-
- 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(!emptyempty($this->title)) {
- $this->graph->title->set($this->title);
- }
- if(!emptyempty($this->subtitle)) {
- $this->graph->subtitle->set($this->subtitle);
- }
- else {
- $this->graph->subtitle->set('('.date('y-m-d').')');
- }
- if(!emptyempty($this->xaxis)) {
- $this->graph->xaxis->title->set($this->xaxis);
- }
- if(!emptyempty($this->yaxis)) {
- $this->graph->yaxis->title->set($this->yaxis);
- }
-
- }
-
-
- 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;
- }
-
-
- function create_barpot($parms,$color='black',$width='0')
- {
- $this->ydata = $parms;
- $this->barpot = new barplot($this->ydata);
- $this->barpot->setfillcolor($color);
- if(!emptyempty($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->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();
- }
- }
-
- ?>
|
|
|
|