Php generate various statistical charts instance _ PHP Tutorial

Source: Internet
Author: User
Php generates various statistical graph instances .. Jpgraph is an object-oriented graph creation function library. It can be used to generate commonly used charts, such as bar charts, pie charts, Gantt charts, and mesh charts. Supported graph. jpgraph open source project introduction
Jpgraph is a function library for creating object-oriented graphs. It can be used to generate commonly used charts, such as bar charts, pie charts, Gantt charts, and mesh charts. Supported image formats include gif, jpg, and png.

Jpgraph is an open-source class library dedicated to providing charts written using php tutorials. It makes plotting a very simple task. you only need to extract the relevant data from the database tutorial, define the title, chart type, and so on, you only need to learn a few built-in jpgraph functions (you can refer to the examples of jpgraph), and use a few simple lines of code to make awesome charts!

2.jpg raph download, installation, and use
Jpgraph official: http://jpgraph.net/download/

When downloading, note that jpgraph is divided into several versions. you can determine which version of jpgraph library file to download based on your php version.

It is relatively simple to install, but pay attention to the following two points:

Make sure that your php version is 4.04 at the lowest (but I guess it is usually over 5.0 now, it should not be a problem ).
In addition, the gd library must be supported. jpgraph is based on the gd library, and the gd Library version can be used at will.
After jpgraph is downloaded, decompress the compressed package to any directory and go to the jpgraph-version Directory. There are two directories. The other txt files are simple instructions. The docportal directory is a help system directory, which includes installation and configuration, usage instructions, and function introduction. if you have the patience, take a good look.

We mainly need the examples directory, which contains the jpgraph library files and a lot of sample files. we can view the sample files to learn about it, in this way, learning to use 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, through which you can set relevant parameters of jpgraph, such as setting the cache (cache) folder of jpgraph, and the ttf (font) folder.

Note:

The cache (cache) folder path can be customized, while the ttf (font) folder must be % system %/fonts.
Make sure that php has the write permission on the cache folder.
Note that the program is UTF-8 encoded.
3. Simple example
There are too many examples of jpgraph programs in the examples directory, so I will not be too arrogant. I will briefly explain the writing method and the previous small example.

First, reference the file containing the jpgraph library in the program:

Require_once ('jpgraph/jpgraph. php ');
Require_once ('jpgraph/jpgraph_line.php ');
Then, create a graphic object:

$ Graph = new graph (350,250 );
Set various style attribute parameters for graphics and charts:

$ Graph-> setscale ("textlin ");
$ Graph-> img-> setmargin (30,90, 40,50 );
$ Graph-> xaxis-> setfont (ff_font1, fs_bold );
Display at last:

$ Graph-> add ($ lineplot );
$ Graph-> stroke ();
The following is a simple but complete sample jpgraph program:

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 ();
?>
The basic introduction to the jpgraph Library is over. Next, I will release the class files that have encapsulated the jpgraph Library. at the same time, I may provide a summary of common jpgraph problems, thank you for your comments.

Jpgraph is a function library for creating object-oriented graphics. It can be used to generate commonly used charts, such as bar charts, pie charts, Gantt charts, and mesh charts. Supported graph...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.