Jpgraph Introduction
In the past, the use of PHP to draw a complex abstract drawing function must be mastered, or the use of some online download style, pie chart class to achieve. There is no unified chart class to implement the rapid development of graphs.
Now we have a new choice: Jpgraph. A class library that provides charts specifically. It makes drawing a very simple thing, you just get the relevant data from the database, define the title, the type of the chart, and then leave it to jpgraph, with only a handful of jpgraph built-in functions (which you can learn with reference to jpgraph examples), You can draw a very dazzling chart!
Jpgraph Installation Method:
1,
Download the latest version to the major websites first. such as: http://www.jb51.net/codes/38194.html
2,
Make sure your PHP version is at least 4.04 (preferably 4.1.1) and supports the GD library. You must make sure that the GD library is functioning correctly, and you can determine by running phpinfo () to see if the information in the GD library exists. Also require that the GD library version should be 2.0, rather than 1.0.
3,
Extract the downloaded Jpgraph compressed package to any folder.
4,
Sets the jpgraph.php (jpgraph primary configuration file). Sets the cache (cache) folder for Jpgraph, and the TTF (font) folder.
In lines 35 and 38, respectively.
Copy Code code as follows:
//DEFINE ("Cache_dir", "/tmp/jpgraph_cache/");
//DEFINE ("Ttf_dir", "/usr/x11r6/lib/x11/fonts/truetype/");
The Linux system is changed to:
Copy Code code as follows:
DEFINE ("Cache_dir", "/tmp/jpgraph_cache/"); '
DEFINE ("Ttf_dir", "/usr/x11r6/lib/x11/fonts/truetype/");
The Windows system is changed to:
Copy Code code as follows:
DEFINE ("Cache_dir", "c:/apache/htdocs/jpgraph_cache/"); '
DEFINE ("Ttf_dir", "c:/windows/fonts");
Precautions:
(1) the cache (cache) folder path can be defined by itself, and the TTF (font) folder must be%system%/fonts.
(2) Make sure that PHP has write permission to the cache folder.
5,
The above settings can be used after the jpgraph, you can first copy the jpgraph example to the Htdocs folder, run a look. Oh, more than 200 examples, including various types of charts, enough to learn for a while.
In the actual use, the author also encountered some problems, such as font errors, and so on, but also in the study ...
Reading data from a database into a jpgraph chart
1,
example16.2.php files in the./src/examples directory and files in the./src directory jpgraph_bar.php, jpgraph_gradient.php, jpgraph_line.php, jpgraph _plotmark.inc, jpgraph.php copy to the same directory.
2,
Create database JPG, database table test
Create 2 fields:
ID (primary key): int
Number:int
and add some data
3,
Modify example16.2.php
The modified code
Copy Code code as follows:
<?php
Include ("jpgraph.php");
Include ("jpgraph_line.php");
Include ("jpgraph_bar.php");
$connect =mysql_connect ("localhost", "root", "");
mysql_select_db ("JPG", $connect);
$query =mysql_query ("SELECT * from Test", $connect);
$i = 0;
while ($array =mysql_fetch_array ($query)) {
$l 2datay[$i]= $array ["number"];
$i + +;
}
Mysql_close ($connect);
Create the graph.
$graph = new Graph (400,200, "Auto");
$graph->setscale ("Textlin");
$graph->img->setmargin (40,130,20,40);
$graph->setshadow ();
Create the bar plot
$bplot = new Barplot ($l 2datay);
$bplot->setfillcolor ("Orange");
$bplot->setlegend ("result");
Add the plots to T ' he graph
$graph->add ($bplot);
$graph->title->set ("Adding a line plot to a bar graph v1");
$graph->xaxis->title->set ("X-title");
$graph->yaxis->title->set ("Y-title");
$graph->title->setfont (Ff_font1,fs_bold);
$graph->yaxis->title->setfont (Ff_font1,fs_bold);
$graph->xaxis->title->setfont (Ff_font1,fs_bold);
$graph->xaxis->setticklabels ($datax);
$graph->xaxis->settexttickinterval (2);
Display the graph
$graph->stroke ();
?>
4,
Refresh the page to see the results
Historical information
Network optimization, 300*200 picture size is about 2K, but ordinary pictures than jpgraph generated large 4-5k
Supports GD1 and GD2, and Jpgraph automatically detects which libraries are installed on the system
supports a variety of chart styles, including common mesh, style, pie (2d and 3D), etc.
Support 3D Transparent, alpha hybrid technology
Supports more than 400 named colors
Supports graphics with background pictures in a variety of ways
Supports the generated chart network cache to mitigate HTTP server burdens
September 17, 2009: Update Jpgraph 1.27.1.
April 18, 2009: Update jpgraph 1.27 and Jpgraph 2.34.
December 2: Today, two Phpchina friends join our translation team: hedgehogs and Deman.
June 28, 2008: Jpgraph Chinese station released, although this is made with ASP Web site, but does not mean that webmaster preference for ASP
June 15, 2008: Jpgraph 1.26 released. Fixed the pie chart slice problem. Maybe this will be the last version of the 1.x release announcing the end of the update 2
008 Year June 14: Jpgraph 2.33 release