Create Pie Chart using PHP

I am aware that PHP has image creation capabilities but I haven’t explored these yet.

I have data which I will pull from a MySQL database and would like to use to create a pie chart much like Excel.

What I need to know is if PHP capable of creating pie charts?

Has anyone done this? Is there an ‘add-on’ required to work with PHP for this to happen?

There are libraries available that will make this much easier. See:

http://www.aditus.nu/jpgraph/ - Pretty much the standard graphing library for PHP
http://pear.php.net/package/Image_Graph - Haven’t tried this one myself
http://www.maani.us/charts/index.php - Produces Flash graphs

Sean :slight_smile:

Thanks seanf.

Have you tried the flash graphs - http://www.maani.us/charts/index.php?

I experimented with it recently for a project I am working on and was quite impressed. It can produce some good looking results, but the API (the parts of the library you work with to create a graph) could use some improvements

Sean :slight_smile:

The PHP/Flash graphics is effectivley the XML/Flash Graphs product with a PHP script to produce the XML from an array - at the moment at least, whether there are plans to make the PHP API more advanced than that I don’t know.

I really like the XML/Flash Graphs thingy though - I’ve been using it alot recently and I love the way I can create / manipulate the XML as much as I want with PHP’s functions for it and then just send the clean XML output to XML/SWF Graph. Well worth a look, IMO.

From the users point of view the graph will load a little slower with PHP/SWF and XML/SWF graphs because the flash app has to process the graph data after it has loaded and render the chart, you also have no way of caching the output as you can do with a traditional graph-image library. However the results are very attractive and the way you can animate the output (for example) is very slick is done tastefully!

If you like using XML, why not use SVG :slight_smile:

http://ren.dotgeek.org/ex/example.php

What I need to know is if PHP capable of creating pie charts?

Yes and with ease. Gd library is what makes image manipulation/creation possible in php.GD has a function that is perfect for this. imagefilledarc

better yet… heres my example of using it.

live example

source code