Powerful third-party chart class library available for TP-jpgraph

Source: Internet
Author: User

Charts, such as line charts, pie charts, and column charts, are often required during routine development. complex abstract drawing functions are required for drawing with PHP, or, you can use some of the classes of bar chart and pie chart downloaded from the Internet to quickly develop charts without a uniform chart class. This is very troublesome.
Now we have a new option: jpgraph. Class Libraries dedicated to providing charts. It makes plotting a very simple task. You only need to extract the relevant data from the database, define the title, chart type, and then hand over the data to jpgraph, you only need to know a few built-in jpgraph functions (you can refer to the examples of jpgraph) to draw a Very dazzling chart!

Requirement: Make sure that your PHP version is 4.04 (preferably 4.1.1) and supports the GD library. Make sure that the GD library runs properly. You can run phpinfo () to check whether the GD library information exists. At the same time, the version of the GD library must be 2.0, instead of 1.0.
The jpgraph in the attachment has been changed to support thinkphp, which can generate pie charts, line charts, and column charts. You only need to add them to a third-party class library according to the instructions and import them into the class library. Take thinkphp2.1 as an example: First extract the jpgraph.zip plug-in the attachment, copy it to the thinkphp/vendor directory, and then copy the driver file "chart. class. copy "php" to 'thinkphp/lib/think/util '. Under this directory, you can directly use it in the action file.

Version 3.1.2 can be placed as follows: 1. Unzip the jpgraph.zip file to the thinkphp/extend/vendor directory. The directory does not exist. 2. Place chart. Class. php In the thinkphp/extend/library/org/util directory. The directory does not exist. Before using it, please first import the chart class, the method is import ("org. util. Chart.

The following provides some methods for reference.

Class testaction extends action {

// 3D pie chart
Function Index (){
$ Chart = new chart ();
$ Title = "3D pie chart"; // Title
$ DATA = array (20, 27, 45, 75, 90, 10, 20, 40); // data
$ Size = 140; // size
$ Width = 750; // width
$ Height = 350; // height
$ Legend = array ("aaaa", "BBBB", "CCCC", "dddd", "eeee", "ffff", "GGGG", "hhhh"); // description
$ Chart-> create3dpie ($ title, $ data, $ size, $ height, $ width, $ legend );
}

// Bar chart
Function test1 (){
$ Chart = new chart ();
$ Title = "Bar Chart"; // Title
$ DATA = array (20, 27, 45, 75, 90, 10, 80,100); // data
$ Size = 140; // size
$ Width = 750; // width
$ Height = 350; // height
$ Legend = array ("aaaa", "BBBB", "CCCC", "dddd", "eeee", "ffff", "GGGG", "hhhh"); // description
$ Chart-> createcolumnar ($ title, $ data, $ size, $ height, $ width, $ legend );
}
// Line chart
Function test1 (){
$ Chart = new chart ();
$ Title = "Bar Chart"; // Title
$ DATA = array (20, 27, 45, 75, 90, 10, 80,100); // data
$ Size = 140; // size
$ Width = 750; // width
$ Height = 350; // height
$ Legend = array ("aaaa", "BBBB", "CCCC", "dddd", "eeee", "ffff", "GGGG", "hhhh"); // description
$ Chart-> createmonthline ($ title, $ data, $ size, $ height, $ width, $ legend );
}

// Ring chart
Function test1 (){
$ Chart = new chart ();
$ Title = "Bar Chart"; // Title
$ DATA = array (20, 27, 45, 75, 90, 10, 80,100); // data
$ Size = 140; // size
$ Width = 750; // width
$ Height = 350; // height
$ Legend = array ("aaaa", "BBBB", "CCCC", "dddd", "eeee", "ffff", "GGGG", "hhhh"); // description
$ Chart-> createring ($ title, $ data, $ size, $ height, $ width, $ legend );
}

// Horizontal bar chart
Function Test2 (){
$ Chart = new chart ();
$ Title = "bar Business Chart"; // Title
$ Subtitle = "August 1, June 2012 ";
$ DATA = array (90,100, 80,100,300,500,100,); // data
$ Size = 140; // size
$ Width = 750; // width
$ Height = 350; // height
$ Legend = array ("Zhang San 1", "Zhang San 2", "Zhang San 3", "Zhang San 4", "Zhang San 5", "Zhang San 6", "Zhang San 7 ″, "James 8"); // description
$ Chart = new chart ();
$ Chart-> createhorizoncolumnar ($ title, $ subtitle, $ data, $ size, $ height, $ width, $ legend );
}
}

Note:
1. The $ legend and $ data arrays are index arrays. The subscripts must be continuous. If they are separated, the generated icons will be misplaced.
2. The generated image can be called elsewhere. Use the IMG tag.

PS: phpexcel source code package:

Http://pan.baidu.com/share/link? Consumer id = 471807 & UK = 100806524

Unzip the password: www.ithinkphp.com

Powerful third-party chart class library available for TP-jpgraph

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.