<?php教程
/**
* ecshop jpgraph圖表類庫
* ==============================================================
* 利用開源的jpgraph庫實現對各類型數據以圖表,走勢圖的形式表現出來。
* ==============================================================
**/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 = ''; //圖表類型? (textlin,textlog,intlin)
var $yscale = ''; // (log,)
var $xgrid = false; //x軸網格顯示
var $ygrid = false; //y軸網格顯示
var $title = ''; //標題
var $subtitle = ''; //子標題(一般為日期)
var $xaxis = ''; //x軸名稱
var $yaxis = ''; //y軸名稱/*margin position*/
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 __construct($parms,$width,$height)
{
cls_jpgraph($parms,$width,$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(!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(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').')'); //默認子標題設置為當前日期
}
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();
}
}?>