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:
Serve the chart/plot “inline” with the page. The options I can see here are:
a. SVG (Scruffy or SVG::Graph)
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.