|
|
PHP Object wrapper for the Google Chart API
A simple PHP Object wrapper for the Google Chart API. Should help anyone who needs to automate the building of the Google Chart url. Supports all types of charts.
Get the code here: code link
Pie Chart Example
pie chart using the gPieChart class.
code:
$piChart = new gPieChart;
$piChart->addDataSet(array(112,315,66,40));
$piChart->valueLabels = array("first", "second", "third","fourth");
$piChart->dataColors = array("ff3344", "11ff11", "22aacc", "3333aa");
Check out the Examples
Notes
- Limitations as it currently sits: no support for lxy, or scatter-plots. lxy and scatter should be available soon…
- scaling is in place, but kinda useless until I get axes marked correctly. That’s tops on my priority list for this.
- Some extras still need implementation (chart background, image background, data point markers, etc.)
I am pleased with how the code is shaping up. I haven’t had much of an opportunity in the past to play with inheritence and polymorphism in PHP.
Currently I have it set up where like so (in terms of inheritence):
- gChart (the base chart class)
- gPieChart (has a simple set3D(bool) function)
- gLineChart
- gBarChart
- gStackedBarChart
- gGroupedBarChart
I will probably refactor that sometime soon. But, I’m happy with how it works currently.
I was concerned for a bit about how I would be losing the ability to change the chart type with one line of code (as I could did with the first draft) by breaking chart types out into separate classes. The fact of the matter is that really, no one is very likely to be doing that anyway. So, better code at (perhaps) the sake of some usability…
