Home >Backend Development >PHP Tutorial >Introduction to the use of jpgraph class library in php_PHP tutorial
With Jpgraph, as long as you understand some of its built-in functions, you can easily draw line charts, column charts, pie charts and other charts.
First make sure that PHP has the Gd2 extension turned on:
Open PHP.ini, locate extension=php_gd2.dll, and delete the semicolon in front of it.
Then download Jpgraph, http://www.aditus.nu/jpgraph/, and extract it to a folder. Such as E:Softwarewebwwwjpgraph.
Open PHP.ini, modify the include_path parameter, add the path of Jpgraph, such as include_path=",;E:Softwarewebwwwjpgraph", and restart the Apache service.
This way the environment is ready.
A routine is attached below.
// Create a Graph class, 350 is the width, 250 is the length, auto: means that the generated cache file name is the file name + extension of the file (.jpg .png .gif...)
$graph = new Graph(350,250,"auto");
//Set the scale type. The x-axis scale can be used as a straight-line scale for text labeling, and the y-axis is a straight-line scale.
$graph->SetScale("textlin");
// Create a coordinate class and inject y-axis data into
$lineplot=new LinePlot($ydata);
// Set the y-axis connection line to blue
$lineplot->SetColor("blue");
// Inject the coordinate class into the icon class
$graph->Add($lineplot);
// Display graph
$graph->Stroke(); ?>