I was rather bored the other day when i found out about google’s chart api, which allows you to create a chart by linking to a url with some things in it.. you can find more about it in here.
Well, I became bored somedays later, and started creating a class to work with it. This class would create and add all the information needed to the base url, After reading and adding a lot of things into the class, I made a rather decent php chart for he creation of charts using google’s api. After googling “php google charts api” I found out there are many other similar classes, which make mine look … plain… i wil exapand it a little and then present the final one, currantly it only supports a limited number of google’s settings. I will add all settings, and eventually have a complete class. Also, i found out, that my class has something in favor.. it’s really simple to use
.
Download here:
For instructions,
Ok let’s get to the code.
Ok, now $test becomes our gchart object, the only thing left is to set the chart’s properties and it’s data. To do this you use gchart’s function set(); and setdata(); like this.
1 2 3 4 5 6 7 8 9 | $test->setdata("t","30,20,75"); $test->set("type","bvs"); $test->set("size","500x350"); $test->set("title","Test!"); $test->set("labels","Test1|Test2|Test3"); $test->set("title style","#3dcfcc,15"); $test->set("legend position","bottom"); $test->set("legend","Test1|Test2|Test3"); $test->set("colors","ff0000|00ff00|0000ff"); |
The explanation containing all parameters for set(); are at the bottom.
now that we have setuped the data and the style plus all other properties we desire, we have to create an array listing the parameters we setuped before. You can create a variable and contain the array there or use it directly as a function parameter with geturl();.
1 2 3 4 5 6 7 8 9 10 | $params = array( "type", "data", "size", "title", "titleS", "labels", "legend_position", "legend", "colors" ); |
And finally, we simply use geturl(); within the image’s html code.
1 | <img src="%3C?php%20$test-%20/%3Egeturl%28$params%29;?%3E" alt="Chart" /> |
Ok that’s it.. the above code would generate this:
Set(); settings
( C = Chart, L = Linear, S = Style, P = Position)
- Type(pie, pie3, line chart, spread xy, sparkline, bhs, bvs, bhg, bvg, venn diagram, scattered plot, radar chart, map, google-o-meter,
- size(widthxheight)
- labels(label 1 | label 2 | label 3)
- Ctitle(title)
- titleS(color, size)
- legend(label 1 | label 2 | label 3)
- legend_position(bottom/top/right/left)
setdata($encoding,$data);
you should refer to Google’s api page, in order to know what type pf encoding to use. $data is a list of comma seperated values.
Missing
I will be adding functionality for these settings soon
- Dscalling
- Lgradient
- Lstripes
- colors
- solidfill