Introducing gchartrb - Ruby wrapper around the Google Chart API

20 views
Skip to first unread message

Deepak Jois

unread,
Dec 9, 2007, 11:01:47 PM12/9/07
to singap...@googlegroups.com
Hi
As you may already know, Google introduced its Charting API which can help you generate some very good Graphs/Charts using their Online querystring based API, http://code.google.com/apis/chart

I wrote a Ruby wrapper around it which is located at http://code.google.com/p/gchartrb . A lot of the inspiration for the API came from te Gruff library. The code is currently in subversion, but most of the imprtant features are already done. I am hoping to make a release by the end of the week.

Feedback and comments are appreciated :)

Deepak

choonkeat

unread,
Dec 10, 2007, 12:08:05 AM12/10/07
to singap...@googlegroups.com
Beautiful! I've put it into use for my backend stats already!

Qn: Any chance all the options become a "hash" argument at the end of the initialize methods so we can customize in 1 shot? I find possible booleans easier to understand/discover like that

lc = GoogleChart::LineChart.new('320x200', "Title" , {
  is_xy: true, show_legend: false, show_labels: true,
})


Qn: Convenient to add a 'yield self if block_given?" at the bottom of each initialize method, so that I can use it block style?

lc = GoogleChart::LineChart.new('320x200', "Title" ) do |c|
  c.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
  c.data "Trend 2", [1,2,3,4,5,6], '00ff00'
  c.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
end


--
choonkeat

Deepak Jois

unread,
Dec 10, 2007, 12:24:59 AM12/10/07
to singap...@googlegroups.com
On 12/10/07, choonkeat <choo...@gmail.com> wrote:
Beautiful! I've put it into use for my backend stats already!

Qn: Any chance all the options become a "hash" argument at the end of the initialize methods so we can customize in 1 shot? I find possible booleans easier to understand/discover like that

lc = GoogleChart::LineChart.new('320x200', "Title" , {
  is_xy: true, show_legend: false, show_labels: true,
})

Good suggestion. Will think of a nice way to include that.

I also wanted to add that you can directly manipulate the hash used to generate the URL by looking for the params attribute. This is useful if you want features that have not been implemented yet.

Qn: Convenient to add a 'yield self if block_given?" at the bottom of each initialize method, so that I can use it block style?

lc = GoogleChart:: LineChart.new('320x200', "Title" ) do |c|
  c.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
  c. data "Trend 2", [1,2,3,4,5,6], '00ff00'
  c. data "Trend 3", [6,5,4,3,2,1], 'ff0000'
end

Great suggestion again.. let me look at that. But you can always send patches :)..

Deepak

JasonOng

unread,
Dec 10, 2007, 1:32:00 AM12/10/07
to Singapore Ruby Brigade
Thanks Deepak! Now we can have a simple (and cheap) powerful
alternative to charting in ruby. :)

On Dec 10, 1:24 pm, "Deepak Jois" <deepak.j...@gmail.com> wrote:
> On 12/10/07, choonkeat <choonk...@gmail.com> wrote:
>
>
>
> > Beautiful! I've put it into use for my backend stats already!
>
> > Qn: Any chance all the options become a "hash" argument at the end of the
> > initialize methods so we can customize in 1 shot? I find possible booleans
> > easier to understand/discover like that
>
> > lc = GoogleChart::LineChart.new('320x200', "Title" , {
> > is_xy: true, show_legend: false, show_labels: true,
> > })
>
> Good suggestion. Will think of a nice way to include that.
>
> I also wanted to add that you can directly manipulate the hash used to
> generate the URL by
> looking for the params attribute. This is useful if you want features that
> have not been implemented yet.
>
> Qn: Convenient to add a 'yield self if block_given?" at the bottom of each
>
> > initialize method, so that I can use it block style?
>
> > lc = GoogleChart::LineChart.new('320x200', "Title" ) do |c|
> > c.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
> > c.data "Trend 2", [1,2,3,4,5,6], '00ff00'
> > c.data "Trend 3", [6,5,4,3,2,1], 'ff0000'

choonkeat

unread,
Dec 10, 2007, 1:37:28 AM12/10/07
to singap...@googlegroups.com
There you go, my attempt #1 http://pastie.caboo.se/private/5gtimkszj2x9vmtclwkw

I don't have a solution for bar_chart.rb (regarding the call to set_chart_type) at the moment.

Cheers
--
choonkeat

On Dec 10, 2007 2:32 PM, JasonOng <velv...@gmail.com> wrote:

Thanks Deepak! Now we can have a simple (and cheap) powerful
alternative to charting in ruby. :)

On Dec 10, 1:24 pm, "Deepak Jois" <deepak.j...@gmail.com > wrote:
> On 12/10/07, choonkeat <choonk...@gmail.com> wrote:
>
>
>
> > Beautiful! I've put it into use for my backend stats already!
>
> > Qn: Any chance all the options become a "hash" argument at the end of the
> > initialize methods so we can customize in 1 shot? I find possible booleans
> > easier to understand/discover like that
>
> > lc = GoogleChart::LineChart.new('320x200', "Title" , {
> >   is_xy: true, show_legend: false, show_labels: true,
> > })
>
> Good suggestion. Will think of a nice way to include that.
>
> I also wanted to add that you can directly manipulate the hash used to
> generate the URL by
> looking for the params attribute. This is useful if you want features that
> have not been implemented yet.
>
> Qn: Convenient to add a 'yield self if block_given?" at the bottom of each
>
> > initialize method, so that I can use it block style?
>
> > lc = GoogleChart::LineChart.new ('320x200', "Title" ) do |c|

Ezwan Aizat Abdullah faiz

unread,
Dec 10, 2007, 3:33:52 AM12/10/07
to singap...@googlegroups.com
Hi guys,

Just saw this on Riding on Rails, he also created his own gem, though the link for it isn't up yet.


Regards,
Aizat


aizatto - sleep to the power of z -_-^zzz



Deepak Jois

unread,
Dec 11, 2007, 3:45:40 AM12/11/07
to singap...@googlegroups.com


On 12/10/07, Ezwan Aizat Abdullah faiz <aizat...@gmail.com> wrote:
Hi guys,

Just saw this on Riding on Rails, he also created his own gem, though the link for it isn't up yet.



Nothing like a bit of competition to keep you motivated :). I finally got off my back and finished the RDoc documentation and also published a gem.

http://gchartrb.rubyforge.org

Deepak

JasonOng

unread,
Dec 11, 2007, 4:57:03 AM12/11/07
to Singapore Ruby Brigade
Awesome. Great job Deepak!

On Dec 11, 4:45 pm, "Deepak Jois" <deepak.j...@gmail.com> wrote:

chu...@gmail.com

unread,
Dec 11, 2007, 11:38:56 AM12/11/07
to Singapore Ruby Brigade
Damn quick, Deepak! I like it, something we'll definitely be
considering using when we have new reporting/stats work that needs to
be done.

Some link juice + a bit of publicity for you:
http://blog.codefront.net/2007/12/12/gchartrb-ruby-google-chart-api/

Nice work!

Sau Sheong Chang

unread,
Dec 11, 2007, 9:32:02 PM12/11/07
to singap...@googlegroups.com
Excellent Deepak! I was thinking of using the Google Charting API the other day for one of my apps and here it is, a Ruby wrapper literally just at my doorstep. Really cool!

Nicolas Sanguinetti

unread,
Dec 13, 2007, 7:55:36 PM12/13/07
to Singapore Ruby Brigade
On Dec 10, 3:08 am, choonkeat <choonk...@gmail.com> wrote:
> Qn: Convenient to add a 'yield self if block_given?" at the bottom of each
> initialize method, so that I can use it block style?
>
> lc = GoogleChart::LineChart.new('320x200', "Title") do |c|
> c.data "Trend 1", [5,4,3,1,3,5,6], '0000ff'
> c.data "Trend 2", [1,2,3,4,5,6], '00ff00'
> c.data "Trend 3", [6,5,4,3,2,1], 'ff0000'
> end

Even further, alias :to_s :to_url
So you can just

puts GoogleChart::LineChart.new('320x200', "Title") do |c|
c.data ....
end

That way you can just pass the graph into an string interpolation and
have ruby call to_s implicitly :)

Best,
-Nicolas

Deepak Jois

unread,
Dec 13, 2007, 8:58:03 PM12/13/07
to singap...@googlegroups.com


On 12/12/07, chu...@gmail.com <chu...@gmail.com> wrote:

Some link juice + a bit of publicity for you:
http://blog.codefront.net/2007/12/12/gchartrb-ruby-google-chart-api/


Looks like the link juice really did wonders. I am getting a lot of referral visits to the Google Code site :). Thanks!

Harish Mallipeddi

unread,
Dec 13, 2007, 10:14:16 PM12/13/07
to singap...@googlegroups.com
Yup Chu Yeow is the man to go to get some referral traffic. Every time that he ever linked to my blog, I noticed a huge spike :)
--
Harish Mallipeddi
Software Engineer
Work: http://www.circos.com
Blog: http://poundbang.in
Mobile: (+65) 96976230
GTalk: harish.mallipeddi

chu...@gmail.com

unread,
Dec 14, 2007, 3:07:21 AM12/14/07
to Singapore Ruby Brigade
Heh my normal traffic isn't that crazy though - this time my blog post
got DZone'd - http://dzone.com/links/gchartrb_ruby_google_chart_api.html



On Dec 14, 11:14 am, "Harish Mallipeddi" <harish.mallipe...@gmail.com>
wrote:
> Yup Chu Yeow is the man to go to get some referral traffic. Every time that
> he ever linked to my blog, I noticed a huge spike :)
>
> On Dec 14, 2007 9:58 AM, Deepak Jois <deepak.j...@gmail.com> wrote:

JasonOng

unread,
Dec 15, 2007, 12:19:23 AM12/15/07
to Singapore Ruby Brigade
Yeah I saw your post on DZone :)

On Dec 14, 4:07 pm, "chuy...@gmail.com" <chuy...@gmail.com> wrote:
> Heh my normal traffic isn't that crazy though - this time my blog post
> got DZone'd -http://dzone.com/links/gchartrb_ruby_google_chart_api.html
Reply all
Reply to author
Forward
0 new messages