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

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

Jun 13, 2016 am 09:48 AM
ecshop jpgraph php picture chart Tutorial number generate of type Performance

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

?>

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Top 10 Global Digital Virtual Currency Trading Platform Ranking (2025 Authoritative Ranking) Top 10 Global Digital Virtual Currency Trading Platform Ranking (2025 Authoritative Ranking) Mar 06, 2025 pm 04:36 PM

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Top 10 exchanges in the currency circle in 2025 latest digital currency app rankings Top 10 exchanges in the currency circle in 2025 latest digital currency app rankings Feb 27, 2025 pm 06:33 PM

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.

Top 10 digital currency trading platforms The latest list of top 10 digital currency trading platforms Top 10 digital currency trading platforms The latest list of top 10 digital currency trading platforms Mar 17, 2025 pm 05:57 PM

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

See all articles