Jpgraph learning notes for PHP graphic operations

Source: Internet
Author: User
This article mainly introduces the Jpgraph learning notes for PHP graphic operations, and introduces in detail the installation and use of Jpgraph, for more information about how to use Jpgraph in PHP, see the following example. 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.

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.