Home php教程 php手册 php 生成各类统计图实例

php 生成各类统计图实例

Jun 13, 2016 am 09:48 AM
jpgraph php introduce create picture graphics Example object Open source yes generate statistics For project

.jpgraph开源项目介绍
jpgraph是一个面向对象图形创建函数库。可用它来生成柱状图,饼状图,甘特图,网状图等常用到的一些图形。支持的图片格式有gif,jpg和png。

jpgraph是一个开源的利用php教程编写的专门提供图表的类库。它使得作图变成了一件非常简单的事情,你只需从数据库教程中取出相关数据,定义标题,图表类型等内容,你只需要学习掌握为数不多的jpgraph内置函数(可以参照jpgraph附带例子学习),利用简单的几行代码就可以做出超酷超炫的图表来!

2.jpgraph下载安装及使用
jpgraph的官方下载地址是:http://jpgraph.net/download/

下载时要注意,jpgraph分为几个版本,你可以根据你的php版本来确定下载那个版本的jpgraph库文件。

安装的话比较简单,不过需要注意下面两点:

确保你的php版本最低为4.04(不过我估计一般现在都5.0以上了,应该不成问题)。
另外一定要支持gd库,jpgraph是基于gd库的,至于gd库版本则可随意。
下载完成jpgraph后,将压缩包解压到任意目录下,进入到jpgraph-版本号目录下,有两个目录,其他的txt文件为简单使用说明文件,可以看看了解即可。docportal目录为帮助系统目录,其中包括从开始安装配置到使用说明,函数介绍等一应俱全,如果有耐心的话,可以好好看看。

我们主要需要的examples目录,在它里面包含了jpgraph库文件和很多的样例文件,我们可以查看学习它的样例文件,这样学习使用起来jpgraph才是最快的。

在jpgraph库文件目录中有一个名为jpg-config.inc的文件,它是jpgraph的配置文件,通过这里可以设置jpgraph的相关参数,例如设置jpgraph的cache(缓存)文件夹,和ttf(字体)文件夹等内容。

注意事项:

cache(缓存)文件夹路径可以自己定义,而ttf(字体)文件夹必须是%system%/fonts。
确保php对cache(缓存)文件夹有写的权限。
注意程序编码为utf-8编码。
3.简单样例
关于jpgraph的样例程序在examples目录下实在够多,我就不再过多罗嗦,就简单说明一下写法及上一个小例子。

首先在程序开始引用包含jpgraph库文件:

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');
然后开始创建图形对象:

$graph = new graph(350,250);
设置图形及图表的各种样式属性参数:

$graph->setscale("textlin");
$graph->img->setmargin(30,90,40,50);
$graph->xaxis->setfont(ff_font1,fs_bold);
最后进行显示:

$graph->add($lineplot);
$graph->stroke();
下面是一个比较简单的但完整的jpgraph程序样例:

setscale("textlin");
$graph->img->setmargin(30,90,40,50);
$graph->xaxis->setfont(ff_font1,fs_bold);
$graph->title->set("dashed lineplot");

// create the linear plot
$lineplot=new lineplot($ydata);
$lineplot->setlegend("test 1");
$lineplot->setcolor("blue");

// style can also be specified as setstyle([1|2|3|4]) or
// setstyle("solid"|"dotted"|"dashed"|"lobgdashed")
$lineplot->setstyle("dashed");

// add the plot to the graph
$graph->add($lineplot);

// display the graph
$graph->stroke();
?>
到此jpgraph库的基本介绍就结束了,再下一篇我会放出我写的已经封装了jpgraph库的类文件,同时可能会有一篇关于jpgraph常见问题总结的说明,欢迎大家到时候给我提出意见哦。

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

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 Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles