Using the GD2 function to implement chart analysis product data (PHP graphic image Typical Application tutorial 6)

Source: Internet
Author: User
using the GD2 function to implement chart analysis product data (PHP graphic image Typical Application tutorial 6)

The use of charts to analyze product data information is the most commonly used data management model of large and medium-sized enterprises, through the chart to analyze the product can not only be at a glance, but also on the next stage of product planning decision-making, rapid improvement of enterprise economic benefits, thus, the use of charts to analyze product data trends is the foundation of rapid development of enterprises , this article is to introduce the chart analysis product data!

In the previous article, "Using the GD2 function to add row and column labels to a chart (PHP graphic image of a typical application tutorial 5)" We introduced the chart to add row and column labels, then use the GD2 function to implement the chart analysis product data, with the content of the previous article is inseparable, to use the content of the previous article, let us detail!

Technical Essentials

The main application to the array () function and the imagestring () function adds various product data information to the chart, where the imagestring () function is described in detail in the deletion of an article, and array () is also described in detail in the array topic. Here we do not do more detailed introduction, not clear small friends can go to see our previous articles and topics!

Implementation process

(1) loading a picture by imagecreatepng () function, using the array to customize two constants, the specific code is as follows;

<?phpheader ("content-type:text/html; Charset=utf-8 "); $im = Imagecreatefrompng (" Upfile/2.png "); Load a png format picture $data = Array (40,50,60,70,80,90,100), $month = Array ("VB", "VC", "JSP", "JS", "C + +", "JAVA", "PHP"); >

(2) After creating the background image, you can then perform various operations on the background, you must call the Imagecolorallcate () function before the operation to define the color of the drawing image, the specific code is as follows:

$black = Imagecolorallocate ($im, 255,0,0); Set the color value,

(3) After the color value is defined, the Imageline () function is applied to draw the coordinates of the x and Y axes, and the imagestring () function is applied to output the characters x and Y, with the following code:

Imageline ($im, 0,20,0,532, $black);         Set Y axis ordinate imageline ($im, 0,437,585,437, $black);      Set X axis ordinate imagestring ($im, 10,0,5, "Y", $black);       Output character yimagestring ($im, 10,560,422, "X", $black);   Output character X

(4) after the coordinates are created, define 4 variables and assign them an initial value, and apply the FOR Loop statement to loop through the label text, where the output of the untagged text is implemented by calling the Imagestring () function, with the following code:

$x = $y = 209; $x _width = +180; $y _ht = 0;for ($i =0; $i <7; $i + +) {    imagestring ($im, 5, $x-1, $y, $month [$i], $black); Set the distance between the language and the X    -axis imagestring ($im, 5, $x-1, $y +200, $data [$i], $black);  Set the distance between language and quantity    $x + = ($x _width+20);                               Set language to language with a width of 20 pixels between the numbers}

(5) need to output graphics to the browser, the usual practice is to save to a file and output to the browser. This example applies the imagepng () function output image code as follows:

Imagepng ($im, "a.png"); Echo  "

Attention:

The Imagepng () function is sent in PNG format to the browser, if the user requires a different format output, should call its corresponding function, Ruyi gif format sent, should call the Imagegif () function.

(6) After the image processing, you need to call the Imagedestroy () function to release the resources of the image, the code is as follows:

Imagedestroy ($im);                       Releasing image resources

Complete the above steps, then in the browser output address, press ENTER to get the table results:

About PHP Graphics image processing Here we are finished, we have what can be added to the article message, we will promptly add content, then our next topic is not scattered!

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.