Building 3D pie chart with PHP using GD library

This is tutorial about building 3D pie chart with PHP using GD library.Although in my  post of
how to build a line chart with php I have recommended to avoid use of GD library for line chart, yet in  this post I am recommending to use GD Library .Building pie chart is easy with GD library.If you are using Google Analytics ,then you can see that all bar or line chart are created using HTML and CSS where as Pie Charts are created with the help of images.

Follow these steps for  building 3D pie chart with PHP using GD library .

1.)Fill data in an array-Fill all values in an array which are going to be used for pie chart construction.

2). Calculate Sum-Calculate the sum of all elements.

3).Calculate angles-Calculate angle for each item.

4).Create image and color resources-Create an image of desired width and height and assign image resource to different variables for image.

5).Divide color resources-Divide color resources into  two shades.Dark shade will be used for creating 3D effect and light shades will be used for creating main part of pie chart.Remembers corresponding elements of both array should contain similar colors means to say that if first element of $darkcolors contains dark red colors then first element of $colors should contain red or a color which is similar to red.If this doesn’t happen then you graph will look odd.

6).Create outer area of pie chart-First filled the outer are of circle with dark colors for 3D effect.

7).Build the main pie-chart-Build the main pie chart using light colors.

8).Show the output-Set header for image and display the chart.

Your pie chart is now completed you can copy the entire code from here.

Output of the script is here.

3D Pie Chart

3D Pie Chart