Skip to Content »

Michi’s blog » Riding the Google Charts API bandwagon

 Riding the Google Charts API bandwagon

  • December 13th, 2007
  • 3:05 pm

Last week, the news hit the blogosphere that Google had released a beta API for generating graphs using a reasonably easy and transparent GET parametrisation.

Inspired by this, and inspired by my early playing around with Ruby on Rails, I decided to whack together a Rails plugin that takes care of building the Google Charts IMG tag using what I hope is reasonably easy to use syntax.

I have a test-site using random data up for playing around with it.

The test-site as such runs on Ruby on Rails. The controller does some parsing and setting up of relevant arrays, and primarily generates random data for plotting.

The view has the following source code:

<%= google_chart(@data, @alt_text, @options)  %>

<p><% form_tag "" do %>

<label for="options[type]">Type</label>
<%= select_tag "options[type]", options_for_select(@typeopts,@options["type"])
%>

<label for="options[title]">Title</label>
<%= text_field_tag "options[title]", @options["title"] %>

<label for="options[encoding]">Granularity</label>
<%= select_tag "options[encoding]", options_for_select(@encopts,@options["encoding"]) %>

<%= hidden_field_tag "datalength", 3 %>
<%= hidden_field_tag "dslengthmin", 5 %>
<%= hidden_field_tag "dslengthmax", 50 %>
<%= hidden_field_tag "dsmin", 0 %>
<%= hidden_field_tag "dsmax", 10000 %>

<%= submit_tag %>
</p>
<% end %>
 

where the @options array is populated with the options tag from the input pretty straight off.

The whole plugin resides at a project of its own at rubyforge. So far, I have not yet implemented color handling, grid lines or marker setting. I’m happy to share code responsibility or getting suggestions for how to handle the outstanding issues or improve on the code. Just get in touch with me if you feel like contributing.

Want your say?

* Required fields. Your e-mail address will not be published on this site

You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>