Jpgraph is a graph framework software written in PHP (supported by the GD library). It has rich functions and is easy to call. However, the details of some charts need to be carefully investigated, I will share with you the problems and solutions I encountered during my project.
Install
Jpgraph installation is very simple: Download To The http://sourceforge.net/projects/jpgraph/, extract to the root path of the application.
Example 1
This time, we will take example0.php under the examples directory as an example to explain how to use jpgraph. The example0.php code is as follows:
Code snippet
<? PHP
Include ("../jpgraph. php"); // file to be referenced
Include ("../jpgraph_line.php"); // contains the graph File
// Y-axis data, which is assigned as an array
$ Ydata = array );
// Create a graph class with a width of 350 and a length of 250. Auto: The generated slow-saving file name is the extension name of the file. (.jpg. PNG. gif ......)
$ Graph = New Graph (350,250, "Auto ");
// Set the scale type. The X axis scale can be used as the linear scale for text labeling. The Y axis is a linear scale.
$ Graph-> setscale ("textlin ");
// Create a coordinate class to inject the Y axis data
$ Lineplot = new lineplot ($ ydata );
// Set Y axis to blue
$ Lineplot-> setcolor ("blue ");
// Coordinate injection icon class
$ Graph-> Add ($ lineplot );
// Display chart
$ Graph-> stroke ();?>
Example 2
Code snippet
<? PHP
$ Ydata = array );
// X-axis data, marked as X-axis
$ Xdata = array ('2017-3-01 ', '2017-3-03', '2017-3-05 ', '2017-3-07', '2017-3-09 ', '2014-03-01 ', '2014-3-11', '2014-3-13 ', '2014-3-15 ');
$ Graph = New Graph (350,150, "Auto ");
$ Graph-> setscale ("textlin ");
// Set the chart title
$ Graph-> title-> set ('example ');
$ Lineplot = new lineplot ($ ydata );
$ Graph-> Add ($ lineplot );
// Set the four-byte margin of the gray scale of the chart. The order is from left to right.
$ Graph-> IMG-> setmargin (60, 20, 20 );
// Set the output file format to JPG. The default value is PNG.
$ Graph-> IMG-> setimgformat ("Jpeg ");
// The Y axis coordinate points are in the shape of a diamond
$ Lineplot-> mark-> SetType (MARK_DIAMOND );
// Add the x axis Annotation
$ Graph-> xaxis-> SetTickLabels ($ xdata );
// Locate the vertical position indicated on the x axis at the bottom
$ Graph-> xaxis-> SetPos ("min ");
// Set the x-axis text to italic, bold, and 6 Characters
$ Graph-> xaxis-> SetFont (FF_ARIAL, FS_BOLD, 6 );
// Set the text skew of the x axis to 45 degrees. Note: The preceding SetFont must be FF_ARIAL.
$ Graph-> xaxis-> SetLabelAngle (45 );
// The x axis scale interval is 2
$ Graph-> xaxis-> SetTextLabelInterval (2 );
// The title and y-axis title are in the Standard font.
$ Graph-> title-> SetFont (FF_FONT1, FS_BOLD, 2 );
$ Graph-> yaxis-> title-> SetFont (FF_FONT1, FS_BOLD );
// Y axis coordinate point line is blue deepen bold
$ Lineplot-> SetColor ("blue: 0.5 ");
$ Lineplot-> SetWeight (2 );
$ Graph-> yaxis-> SetColor ("black ");
$ Graph-> yaxis-> SetWeight (2 );
// Shadow effect
$ Graph-> SetShadow ();
// Display the image
$ Graph-> Stroke ();?>
Possible problems
Due to image output, some display problems may occur in some systems with incorrect GUI configurations. The most common problem is "cannot find XX font (such as FF_ARIAL font)". In this case, we can take the following steps to solve the problem:
1. first, list the fonts in a system (such as a Windows system) that has these fonts or where you can download them, copy them to a directory that can be accessed by a WEB program (assumed as/www/fonts.
Taking FF_ARIAL as an example, we can find arialbd in $ Windows/fonts of windows. ttf, arialbi. ttf, ariali. ttf, arial. ttf and copy it to/www/fonts.
2. Modify the jpgraph. php file.
Find
DEFINE ('ttf _ dir', '/usr/X11R6/lib/X11/fonts/truetype /');
Change this line
DEFINE ('ttf _ dir', '/www/fonts /');
Refresh again