# Best way to serve charts from Rails?

**URL:** <https://www.ruby-forum.com/t/best-way-to-serve-charts-from-rails/78609>\
**Category:** Rails\
**Created:** [December 7, 2006, 7:41am UTC](https://www.ruby-forum.com/t/best-way-to-serve-charts-from-rails/78609 "2006-12-07T07:41:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roytruelove](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roytruelove](https://www.ruby-forum.com/u/roytruelove)\
**Post date:** [December 7, 2006, 7:41am UTC](https://www.ruby-forum.com/t/best-way-to-serve-charts-from-rails/78609/1 "2006-12-07T07:41:39Z")

</div>

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

2. Place an ![]() 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 T.

---

<div class="post-metadata">

**Author:** ![roytruelove](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roytruelove](https://www.ruby-forum.com/u/roytruelove)\
**Post date:** [December 7, 2006, 12:32pm UTC](https://www.ruby-forum.com/t/best-way-to-serve-charts-from-rails/78609/2 "2006-12-07T12:32:31Z")

</div>

Another option is to use Flash-based charts, such as XML/SWF Charts (  
[maani.us](http://www.maani.us/xml_charts/) ) or Fusion Charts (  
[http://www.fusioncharts.com/](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 E.

On 12/7/06, Roy T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> paths to go:
> 
> options).
> 
> >

–  
Cell: 808 782-5046  
Current Location: Melbourne, FL

---

<div class="post-metadata">

**Author:** ![roytruelove](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roytruelove](https://www.ruby-forum.com/u/roytruelove)\
**Post date:** [December 7, 2006, 4:25pm UTC](https://www.ruby-forum.com/t/best-way-to-serve-charts-from-rails/78609/3 "2006-12-07T16:25:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roytruelove](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3ab097/32.png) [@roytruelove](https://www.ruby-forum.com/u/roytruelove)\
**Post date:** [December 7, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/best-way-to-serve-charts-from-rails/78609/4 "2006-12-07T16:37:20Z")

</div>

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.
