Jpgraph learning notes for PHP graphic operations ,. Jpgraph learning notes for PHP graphic operations. This article describes the Jpgraph learning notes for PHP graphic operations. For your reference, I. Jpgraph installation and configuration download the Jpgraph learning notes for PHP graphic operations,
This article describes the Jpgraph learning notes for PHP graphic operations. We will share this with you for your reference. The details are as follows:
1. Jpgraph installation and configuration
Download the Jpgraph installation package
Decompress the package and place it on the disk (preferably with the webpage)
Modify the php. ini file:
1. memory memory_limit = X, at least 32 M
2. the execution time is max_execution_time = X. It takes a lot of time to load complex images. modify the image according to its complexity.
3. cache output_buffering comment out the cache to facilitate debugging
II. basic steps for creating a graph using Jpgraph (required)
1. include the required class library file The code is as follows: require_once ();
2. initialize data The code is as follows: $ data = array ();
It can be fixed data in the php program, that is, static data.
It can be data stored in text files.
It can be data stored in the database.
It can be data transmitted through URL parameters (GET or POST)
3. create a Graph instance The code is as follows: $ graph = new Graph ();
You can set the image size here
4. set the title, X axis title, and y axis title, as well as its font, color, and position.
5. create a graph instance
It can be a line chart, column chart, pie chart, 3d, etc.
6. add data to the graph The code is as follows: $ graph-> Add ();
7. display images The code is as follows: $ graph-> Stroke ();
Now a simple graph is complete.
Note:
Chinese font garbled characters
When Gpgraph displays Chinese characters by default, it regards the Chinese character encoding as gb2312 and converts it to UTF-8 before display. if the file encoding method is gb2312, you only need to set SetFont () set the first parameter of the method to FF_SIMSUN.
If it is UTF-8 encoded, you must first convert the Chinese character encoding to gb2312 so that the Chinese characters can be properly displayed.
The conversion encoding method can use iconv ("UTF-8", "gb2312", $ x );
Some common methods:
$ Graph-> title-> Set ('set the chart title'); $ graph-> tabtitle-> Set ('set the image header text '); $ graph-> xaxis-> title-> Set ("Set the title of the X axis"); $ graph-> yaxis-> title-> Set ("Set the title of the y axis "); $ graph-> SetScale ('textin'); // set the scale value type $ graph-> img-> SetMargin (50, 40, 40, 55); // border spacing (left and right) $ graph-> title-> SetFont (FF_SIMSUN, FS_BOLD, 12); // title font $ graph-> xaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD, 10 ); $ graph-> xaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD, 10); $ graph-> xaxis-> SetFont (FF_SIMSUN, FS_BOLD, 12 ); // font on the coordinate column $ graph-> yaxis-> SetFont (FF_SIMSUN, FS_BOLD, 12); $ graph-> title-> SetColor ('red '); /// title color $ graph-> xaxis-> title-> SetColor ('red'); $ graph-> yaxis-> title-> SetColor ('red '); $ graph-> xaxis-> title-> SetMargin (20); // distance from the coordinate axis $ graph-> yaxis-> title-> SetMargin (20 ); // distance from the Y axis $ linepot-> SetColor ('red'); // Line chart color (line chart) $ linepot-> SetWeight (2 ); // the width of the line $ linepot-> value-> SetFormat ('% 0.1f'); // format the value $ linepot-> value-> show (true ); // Display value $ graph-> SetBackGroundImage (); set the background $ graph-> SetMarginColor ('lightblue'); // set the image color $ graph-> SetShadow (); // $ graph-> Set3DPerspecttive (); // Set 3d/* skew 3D effect 1, 'skew3d_up '2, 'skew3d_down '3, 'skew3d_left' 4, 'skew3d_right '*/$ p1-> SetTheme ('water' ); // set the style $ p1-> SetCenter (0.5, 0.55); // Set the graph position $ graph-> legend-> Pos (0.1, 0.9 ); // Set the comment text position $ graph-> legend-> SetFont (FF_SIMSUN, FS_BOLD, 12); // Set the comment text font
I hope this article will help you with PHP programming.
Articles you may be interested in:
- How php uses Jpgraph to draw a 3D pie chart
- How php uses Jpgraph to draw a pie chart
- How to use Jpgraph to draw a column chart in php
- How php uses Jpgraph to draw complex X-Y coordinate charts
- How php uses Jpgraph to plot a simple X-Y coordinate chart
- Introduction to jpgraph class library in php
- Introduction to using JpGraph php bar chart
- Sample Code of the jpgraph bar chart in a php report
Example: This article describes the Jpgraph learning notes for PHP graphic operations. For your reference, I. download the Jpgraph installation configuration...