Explain in brief how pie chart can be drawn in php GD library.

Getting Fancy with Pie Charts

A little boring, but they introduced you to the process of creating images—define the canvas, define the colors, and then draw and fill. 

Use this same sequence of events to expand your scripts to create charts and graphs, using either static or dynamic data for the data points.

Draws a basic pie chart.


<?php 
    //create the canvas 
 $myImage = ImageCreate(150,150); 

 //set up some colors 
 $white = ImageColorAllocate($myImage, 255, 255, 255); 
 $red  = ImageColorAllocate($myImage, 255, 0, 0); 
 $green = ImageColorAllocate($myImage, 0, 255, 0);
 $blue = ImageColorAllocate($myImage, 0, 0, 255);
 
 //draw a pie 
 ImageFilledArc($myImage, 50, 50, 100, 50, 0, 90, $red, IMG_ARC_PIE);
 ImageFilledArc($myImage, 50, 50, 100, 50, 91, 180 , $green, IMG_ARC_PIE);
 ImageFilledArc($myImage, 50, 50, 100, 50, 181, 360 , $blue, IMG_ARC_PIE);
 
 //output the image to the browser
 header ("Content-type: image/jpeg");
 ImageJpeg($myImage);
 
 //clean up after yourself
 ImageDestroy($myImage);
 
?> 

Out put


which has several attributes: 

  1. The image identifier.
  2. The partial ellipse centered at x.
  3. The partial ellipse centered at y.
  4. The partial ellipse width.
  5. The partial ellipse height.
  6. The partial ellipse start point.
  7. The partial ellipse end point.
  8. Color.
  9. Style.


EmoticonEmoticon