PHP uses Jpgraph to create a histogram showing an example of an annual income statement

Source: Internet
Author: User
This article mainly introduces PHP using Jpgraph to create a histogram to show the annual income and expenditure table effect, combined with a complete example of jpgraph to create a histogram of concrete steps and operation skills, the need for friends can refer to the next

The example in this article is about PHP using Jpgraph to create a histogram to show the annual balance sheet effect. Share to everyone for your reference, as follows:

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.

Site Download Address: http://www.jb51.net/codes/38194.html

There are two ways to configure

(1) Open the installation directory of PHP, edit the php.ini file and modify the Include_path parameter, then add the folder name, such as Include_path = ".;D: \ Wampserver\www\jpgraph "

(2) Restart Apache server to take effect

If 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 ', ' total amount (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:

The above is the whole content of this article, I hope that everyone's study has helped.


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.