Lucky's Graphing Library
- Description
- Using the library
- Examples
Lucky's Graphing library is a set of classes to easily create graphs. It's written in PHP and uses the GD library to draw the images. It can currently generate bar and pie charts.
Lucky's Graphing Library is designed to be very flexible, extendable and configurable. You can change a lot of settings, subclass the base graph class to create your own charts and a lot more.
It has a very simple API and all classes are fully documented, so it should be easy to start with. Also check the examples tab here.

Download
Lucky's Graphing Library is hosted on Launchpad. You can also request features and report bugs there. The launchpad page is here:
https://launchpad.net/lucky-graphing
You can find the download here:
https://launchpad.net/lucky-graphing/trunk
Example Charts
Bar Chart

Pie Chart
First you have to download the library, see the first tab where to find it. Extract it to a directory.
Before you can create your charts, the folder where you extracted the library, should be in your include path. You can do this is the following way:
Before you can create your charts, the folder where you extracted the library, should be in your include path. You can do this is the following way:
Creating a bar chart
Creating a Pie chart
Creating a pie chart goes in almost the same way as a bar chart, this time you only use the Lucky_Graph_Type_Pie class.
Documentation
For more functions: see the API reference:
http://www.return1.net/docs/graphlib
- // Include the library
- include_once 'Lucky/Graph/Type/Bar.php';
- // Create a Bar graph with height 200 (width will depend on how many bars you create)
- $bar = new Lucky_Graph_Type_Bar(200, 200);
- // Add an item
- $bar -> setItem('Cars', 2500);
- $bar -> setItem('Bicycles', 4000);
- $bar -> setItem('Trucks', 2000);
- // Include a legend
- $bar -> setLegendPosition(Lucky_Graph_Type_Bar::LEGEND_BOTTOM);
- // Let the library generate the graph
- $bar -> draw();
- // Output to screen
- $bar -> showImage();
- // Or Save to file
- $bar -> saveToFile('bar.png');
Creating a Pie chart
Creating a pie chart goes in almost the same way as a bar chart, this time you only use the Lucky_Graph_Type_Pie class.
- // Include the library
- include_once 'Lucky/Graph/Type/Pie.php';
- // Create a pie graph with width 200 and height 200
- $pie = new Lucky_Graph_Type_Pie(200, 200);
- // Add an item
- $pie -> setItem('Cars', 2500);
- $pie -> setItem('Bicycles', 4000);
- $pie -> setItem('Trucks', 2000);
- // Include a legend
- $pie -> setLegendPosition(Lucky_Graph_Type_Pie::LEGEND_BOTTOM);
- // Let the library generate the graph
- $pie -> draw();
- // Output to screen
- $pie -> showImage();
- // Or Save to file
- $pie -> saveToFile('pie.png');
Documentation
For more functions: see the API reference:
http://www.return1.net/docs/graphlib

