TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Script Giveaway (http://www.talkphp.com/script-giveaway/)
-   -   GoogleCharts (http://www.talkphp.com/script-giveaway/1704-googlecharts.html)

Karl 12-11-2007 12:05 PM

GoogleCharts
 
2 Attachment(s)
I've been playing with some Google Chart classes over the weekend and I've decided to give the code an early release to see what people think. It's all very basic still, I've mainly concentrated on implementing a flexible system, which I think I've achieved pretty well. I haven't done any performance tuning or anything (and there are a few places where performance improvements are obvious).

Have a play around, let me know what you think. I know there are a lot of improvements that can be made, and I'm eager to see everyones opinions. I don't mind a bit of criticism :-)

There's an example included, but here's an example for the people who wanna see before downloading:

PHP Code:

$pChart = new GoogleChart(GoogleChart::TYPE_BAR_HSTACKED);

$pChart->setSize(200100)
    ->
setGridLines(202015)
    ->
setBackgroundFill(new GoogleChart_Fill_Solid('EFEFEF'))
    ->
setChartFill(new GoogleChart_Fill_LinearGradient(0'76A4FB'0'ffffff'1))
    ->
addData(new GoogleChart_Data_Generic(array(0104010), 'Legend 1''FF0000'))
    ->
addData(new GoogleChart_Data_Generic(array(40201020), 'Legend 2''00FF00'));

echo 
'<img src="' $pChart->render() . '" alt="" />'


maZtah 12-11-2007 12:13 PM

Great script Karl! It's just so advanced, I might have a good read-through :).

Thanks for sharing this with us!

Karl 12-11-2007 12:32 PM

Yes it does use a lot of advanced theories and practices. Feel free to ask any questions and I'll do my best to answer them.

Rendair 12-11-2007 01:17 PM

Nice scripts does, i might have to write a tutorial on writting them advance graphing in GD lol.

bdm 12-11-2007 01:30 PM

I'm assuming this is for greater flexibility, but why:
PHP Code:

echo '<img src="' $pChart->render() . '" alt="" />'

As opposed to making GoogleChart::render() return it.

Karl 12-11-2007 02:30 PM

Basically because I didn't want to mix presentation logic with the core class. Slight inconvenience, but I personally prefer it like this (a lot of other people follow this approach too).

bdm 12-11-2007 02:47 PM

Make sense.

I guess you then have the choice to give that image an id or class.

Thanks.

Wildhoney 12-11-2007 03:35 PM

Why have you commented out the following line in your class constants?

php Code:
const TYPE_BAR_HEIGHT   = 'bh';

bdm 12-11-2007 03:47 PM

Here's a quicky on how to make a transparent backgroun: http://alblue.blogspot.com/2007/12/u...in-google.html

Karl 12-11-2007 03:52 PM

Quote:

Originally Posted by Wildhoney (Post 6262)
Why have you commented out the following line in your class constants?

php Code:
const TYPE_BAR_HEIGHT   = 'bh';

I left it commented because I've not supported it yet. It's also not actually a "type" of chart, so I'm not sure what to do with it yet, need to read over the docs a little more first. I've left it there to remind me to deal with it :-)

jaugusto 12-12-2007 08:01 PM

Great! So it was you who make the first wraper for it!

What I don’t like about Google chart API is the fact axis don’t have nothing to do with values.

Thus, in order for a simple x,y graph to make sense, you have to find the percentage of all your values and then plot them. I mean, if your max value is 150, you must make 150=100% and then calculate all values below it in terms of percentage. Your laber on the x axe will be 150, but your value will be 100%.

Also: it does not work on forums with the [IMG] tag…

It would be usefull for the PHP class to load the url as binary and outputs it as .png, so that it can be recognized everywhere.

Wildhoney 12-14-2007 02:02 PM

Aye, we made the first wrapper :-) and the BEST wrapper! Although I'd stick around as we'll be adding onto it constantly for the next few weeks.

Salathe 12-14-2007 03:20 PM

Quote:

Originally Posted by Wildhoney (Post 6592)
Aye, we made the first wrapper :-) and the BEST wrapper! Although I'd stick around as we'll be adding onto it constantly for the next few weeks.

I beat you to it by days and days, but I'm too scrooge-like to release it into the wild. Good job Karl ^^

jaugusto 12-20-2007 06:51 AM

Hello! Any update?!

Wildhoney 12-20-2007 12:29 PM

No update yet :-) You're going to have to wait a couple of weeks until Christmas period is over! Although Karl's done the extended stuff - not sure if he's released it yet.

What are you waiting on exactly, jaugusto?

jaugusto 01-07-2008 05:00 AM

Thanks for the reply. Waiting on what I posted above ;)

The image generation(to use on forums) and the max value setting.

Merry Cristmas and a Happy New Year, BTW.

Karl 01-07-2008 11:52 AM

I'll get round to releasing an update sometime this week, thanks for checking it out.

thrash56 02-01-2008 05:06 AM

Excellent script, thank you so much for creating it. It is extremely simple to understand and very expandable.

If anyone is having trouble trying to switch encoding on the chart data, there is a small bug that needs correction in the ./GoogleChart.php file. Function setDataEncoding is missing a "m_" before "szDataEnocding." An example of the fix is below.

Code:

        public function setDataEncoding($szEncoding = self::SIMPLE_ENCODING)
        {
                $this->m_szDataEncoding = $szEncoding;
                return $this;
        }


Karl 02-01-2008 12:15 PM

Thanks for reporting that. I really should do some more work on this script, I promised jugusto I would release an update weeks ago.

Karl 02-01-2008 01:22 PM

I've just released v0.2. I would have liked to have spent more time on it but I', unfortunately extremely busy at the moment. Maybe some of our fellow coders can contribute? Failing that, you'll just have to bear with me and I'll try to get another release out within a month.


All times are GMT. The time now is 08:17 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0