Best way to serve charts from Rails?

Best way to serve charts from Rails?
I have been trying to find the “ideal” solution for a while. I’m leaning toward PlotKit, see below for my reasoning.

My department has a database from which I want to serve up dynamic, current charts on my Rails app. When complete, the page will have some controls (30 checkboxes and an ‘Update’ button) to change the graphs based on the user’s preference – the graphs will be updated via AJAX calls. There seem to be two paths to go:

  1.  Serve the chart/plot “inline” with the page. The options I can see here are:
    

a. SVG (Scruffy or SVG::Graph)

b. JavaScript (PlotKit)

c. CSS/HTML

  1.  Place an <img> tag in the page and serve the chart/plot when the browser requests it. The options I see here are:
    

a. Gruff, a ruby library that uses RMagick (which is difficult to install)

b. Scruffy, another Ruby library, doesn’t require RMagick

The big problem with using #2 in my case is that the tag will be updated via an AJAX call. So a total of two requests would be made when the user changes the graph option: one for the new image tag, and one that the browser makes for the actual image. It’s difficult to juggle how the user’s preference gets sent to the server and returned properly.

Another problem with #2 is that web servers aren’t made to serve dynamic images – it really needs a servlet or a controller method that generates/returns the image data (no caching allowed here: I can’t assume any generated graph is the same as any other, since there are so many user options).

Any thoughts or suggestions? I wish Rails was “opinionated” about this sort of thing… I don’t know what I’m doing, really.

Thanks,

Roy Tinker

Another option is to use Flash-based charts, such as XML/SWF Charts (
http://www.maani.us/xml_charts/ ) or Fusion Charts (
http://www.fusioncharts.com/ ). Both of these packages produce
beautiful charts, have some really nice features right out of the box
and have very reasonable license fees. Additionally neither require an
image library to be installed on the server nor do they require any
server side processing.

Just a thought.

V/r
Anthony Eden

Thanks for the links, Fusion charts looks totally sweet!!

Anthony Eden wrote:

I recommend the XML/SWF charts… they work really well with Rails.

Any method will work though… if you’re running Ubuntu then getting RMagick working is easy, and it’s almost as easy on Windows. If you place your chart in a partial, then updating via RJS is really easy.