Introduction to the jpgraph class library in php
- 2020-08-22 21:55:41
- OfStack
With Jpgraph, as long as you know some of its built-in functions, you can easily draw line chart, column chart, pie chart and other charts.
First, make sure that PHP turns on the Gd2 extension:
Open PHP.ini, navigate to extension= php_gd2.dll, and delete the preceding semicolon.
Then download Jpgraph http: / / www aditus. nu jpgraph /, into a folder. Such as E: \ Software \ web \ www \ jpgraph.
Open PHP. ini, modify include_path parameter, increase the path of Jpgraph, such as include_path=", E:\Software\ www\jpgraph", restart the Apache service.
So the environment matches up.
A 1 routine is attached below.
<?php
require_once '../jpgraph/src/jpgraph.php';
require_once '../jpgraph/src/jpgraph_line.php';
require_once '../jpgraph/src/jpgraph_bar.php';
// y Axis data, assigned as an array
$ydata = array(12,4,9,15,11,10,9,7,15,7);
// create Graph Class, 350 As the width, 250 The length, auto : Indicates that the generated cache file name is the file name of the file + extension (.jpg .png .gif ... )
$graph = new Graph(350,250,"auto");
// Set the scale type, x The axis scale can be used as a linear scale for text marking, y The axis is a straight scale
$graph->SetScale("textlin");
// Create the coordinate class that will y Axial data injection
$lineplot=new LinePlot($ydata);
// y Set the axis line to blue
$lineplot->SetColor("blue");
// The coordinate class injects the icon class
$graph->Add($lineplot);
// figure
$graph->Stroke(); ?>