-
jpgraph 生成类型数据以图表走势图的形式表现出来
- <?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='') {
- //开源代码phpfensi.com
- $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);
- }
- }
- /*创建线性关系图表(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(!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->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();
- }
- }
- ?>
原文链接:http://www.phpfensi.com/php/20140819/4462.html
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式