.jpgraph Open Source Project Introduction
jpgraph is an object-oriented graphics creation function library. It can be used to generate some commonly used graphics such as bar charts, pie charts, Gantt charts, and network charts. Supported image formats are gif, jpg and png.
jpgraph is an open source class library written using PHP tutorials that specifically provides charts. It makes drawing a very simple thing. You only need to take out the relevant data from the database tutorial, define the title, chart type, etc. You only need to learn and master a few jpgraph built-in functions (you can refer to the jpgraph included Learn from examples), you can make super cool charts with just a few lines of code!
2.jpgraph download, install and use
The official download address of jpgraph is: http://jpgraph.net/download/
When downloading, please note that jpgraph is divided into several versions. You can determine which version of the jpgraph library file to download according to your php version.
Installation is relatively simple, but you need to pay attention to the following two points:
Make sure your php version is at least 4.04 (but I estimate that it is generally above 5.0 now, so it shouldn’t be a problem).
In addition, the gd library must be supported. jpgraph is based on the gd library, and the gd library version is optional.
After downloading jpgraph, unzip the compressed package to any directory and enter the jpgraph-version number directory. There are two directories. The other txt files are simple usage instructions files, you can take a look and understand. The docportal directory is the help system directory, which includes everything from installation and configuration to usage instructions, function introductions, etc. If you have the patience, you can take a good look.
The examples directory we mainly need contains jpgraph library files and many sample files. We can view and learn its sample files, so that learning and using jpgraph is the fastest.
There is a file named jpg-config.inc in the jpgraph library file directory, which is the configuration file of jpgraph. You can set the relevant parameters of jpgraph through here, such as setting the cache folder of jpgraph, and ttf (font) folder and other contents.
Note:
The cache folder path can be defined by yourself, while the ttf (font) folder must be %system%/fonts.
Make sure php has write permissions on the cache folder.
Note that the program encoding is UTF-8 encoding.
3. Simple example
There are enough sample programs about jpgraph in the examples directory, so I won’t be too wordy and will simply explain the writing method and the previous small example.
First reference the jpgraph library file at the beginning of the program:
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');
Then start creating graphic objects:
$graph = new graph(350,250);
Set various style attribute parameters of graphics and charts:
$graph->setscale("textlin");
$graph->img->setmargin(30,90,40,50);
$graph->xaxis->setfont(ff_font1,fs_bold);
Finally display:
$graph->add($lineplot);
$graph->stroke();
The following is a relatively simple but complete jpgraph program example:
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();
?>
This is the end of the basic introduction to the jpgraph library. In the next article, I will release the class file I wrote that has encapsulated the jpgraph library. At the same time, there may be an explanation on the summary of common problems with jpgraph. You are welcome to give me suggestions at that time. Opinions.