欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

jpgraph 生成类型数据以图表,走势图的形式表现出来_PHP教程

程序员文章站 2024-02-05 09:30:58
...

/**
* 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();
}
}

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/633013.htmlTechArticle?php教程 /** * ecshop jpgraph图表类库 * ============================================================== * 利用开源的jpgraph库实现对各类型数据以图表,走势图的...