The GD2 library can be used to create a wide variety of images, but it is cumbersome to make complex statistical graphs that are only implemented by the GD2 function library. PHP has undergone many changes from birth to maturity, and during this time, many organizations have developed PHP frameworks and library classes. Jpgraph Graphics Library is a very useful and popular representative, not only powerful, but also easy to operate. For example: Apply Jpgraph to create a histogram showing the annual revenue and expenditure situation. (1) The Jpgraph class library, the prime minister should, download the class library of the compressed package, downloaded and then extracted to the directory where the project. : http://download.csdn.net/detail/qq_28602957/9594460
There are two ways to configure (1) Open the installation directory of PHP, edit the php.ini file and modify the include_path parameters, and then add the folder name, such asinclude_path = ".;D: \ Wampserver\www\jpgraph "(2) Restart Apache server to take effectIf you only want to use jpgraph at this site, then extract directly to the project directory. you need to import all of your files into your project using statements such as require_once.
For example, create a index.php page
<?phprequire_once ' jpgraph/src/jpgraph.php '; Import jpgraph class library require_once ' jpgraph/src/jpgraph_bar.php '; The histogram function of importing the Jpgraph class library $data = Array (80, 73, 89, 43, 56, 76, 89, 96, 93, 30, 98, 78); Set up statistics $xdata = array (' Jan ', ' Feb ', ' Mar ', ' Apr ', ' may ', ' June ', ' Jul ', ' the ' ' April ', ' Sep ', ' Oct ', ' Nov ', ' Dec '); $graph = new Gr APH (600, 300); Set the canvas size $graph->setscale (' Textlin '); Sets the coordinate scale type $graph->setshadow (); Set the canvas shadow $graph->img->setmargin (40, 30, 20, 40); Set the chart margin $barplot = new Barplot ($data); Instantiate the Barplot object $barplot->setfillcolor (' Blue '); Set histogram foreground color $barplot->value->show (); Show $graph->add ($barplot); $graph->title->set (Iconv (' utf-8 ', ' gb2312//ignore ', ' * * * * *)];// Set title Iconv prevent Chinese garbled $graph->xaxis->title->set (iconv (' utf-8 ', ' gb2312//ignore ', ' month ')); Set X axis name $graph->xaxis->setticklabels ($xdata);//Set X-axis callout $graph->yaxis->title->set (iconv (' Utf-8 ', ' Gb2312//ignore ', ' totalAmount (million yuan)); Set y-axis name $graph->title->setfont (Ff_simsun, fs_bold); Set the caption Font $graph->xaxis->title->setfont (Ff_simsun, fs_bold); Set X-axis font $graph->yaxis->title->setfont (Ff_simsun, fs_bold); Sets the y-axis font $graph->stroke (); Output image
The result of the operation is:
Use Jpgraph to create a histogram showing annual income and expenditure statement