Michi’s blog » read post

Riding the Google Charts API bandwagon

  • December 13th, 2007

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?

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

post navigation
about
Michi is a recent PhD working in homological algebra. This blog is his outlet for texts with some manner of thought put into them. Over at his LiveJournal intimate details and streams of consciousness might be found.
Not all here is mathematics. All here, though, are my personal thoughts and opinions. Please read the about page (linked above) for more details.
This blog uses statcounter.com for logging and traffic analysis. In order to identify return visitors, this site will issue a cookie on viewing the blog.
buttons

latest comments
search
blogs and links
the rdc* theme