PHP Graphics Operation Jpgraph Learning notes _php Skills

Source: Internet
Author: User
Tags php programming polyline

This article is an example of the PHP graphics operation Jpgraph Learning notes. Share to everyone for your reference, specific as follows:

First, jpgraph installation configuration

Download Jpgraph installation package

After decompression, place the disk (preferably with the page)

To modify the php.ini file:

1, Memory memory_limit=x, at least 32M

2, the execution time max_execution_time=x, for the complex picture loading needs more time, according to the picture complexity makes the corresponding modification

3, Cache output_buffering annotation off cache, easy to debug

Ii. basic steps for creating graphics using jpgraph (necessary)

1, contains the required class library files

Copy Code code as follows:
Require_once ();

2, initialization of data

Copy Code code as follows:
$data =array ();

Can be a fixed data in the PHP program, that is, static data, directly to get
Can be data stored in a text file
Can be data stored in a database
Can be data passed through a URL parameter (get or POST method)

3. Create Graph class Instance

Copy Code code as follows:
$graph =new graph ();

You can set the size of the graphic here

4, set the title, X axis title, Y axis title content, and its font, color, location, etc.

5, create the corresponding diagram instance

Can be line chart, column chart, pie chart, 3d, etc.

6, add the data to the graph

Copy Code code as follows:
$graph->add ();

7. Display Picture

Copy Code code as follows:
$graph->stroke ();

So a simple graphic is done.

Attention:

Chinese font garbled

Gpgraph The default display of Chinese characters is encoding think gb2312, converted to Utf-8 later, if the file encoding is gb2312, just the SetFont () method of the first parameter set to Ff_simsun can
If it is utf-8 encoded, it is necessary to convert encoding to gb2312 so that Chinese characters can be displayed correctly.
Conversion coding methods can be used Iconv ("UTF-8", "gb2312", $x);

Some common methods are:

$graph->title->set (' Set the title of the chart ');
$graph->tabtitle->set (' Set Picture head text ');
$graph->xaxis->title->set ("Set the X-axis title");
$graph->yaxis->title->set ("set title of Y axis"); $graph->setscale (' Textlin '),//Set scale value type $graph->img->setmargin (50,40,40,55),//Border spacing (up and down) $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);//The 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 axis $graph->yaxis->title->setmargin (20),//Distance to Y axis $ Linepot->setcolor (' red ');/The color of the polyline (line chart) $linepot->setweight (2),//The width of the polyline $linepot->value->setformat ('%0. 1f '); The value is formatted $linepot->value->show (TRUE);//Display value $graph->SETBACkgroundimage () Set the background $graph->setmargincolor (' lightblue ');//Set the graphic color $graph->setshadow ();//$graph-> Set3dperspecttive (); Set 3d Effect chart/* Tilt 3D effect 1, ' skew3d_up ' 2, ' Skew3d_down ' 3, ' skew3d_left ' 4, ' skew3d_right '/$p 1->settheme (' water '); Sets the style $p 1->setcenter (0.5,0.55),//sets the position of the graphic $graph->legend->pos (0.1,0.9), or sets the position of the comment text $graph->legend->

 SetFont (ff_simsun,fs_bold,12);//Set font for note text

I hope this article will help you with your 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.