views:

148

answers:

4

I'm trying to make a statistics page where it will show several data and charts.
The charts need to be pictures so that the user can save it/drag-and-drop to his/her personal reports.

I'm using Gruff Graphs for Ruby to produce the charts but I don't know the best way to display the results safe and protected.

Some of my ideas/tries are:

  1. save the chart to a file (jpg, png)? problem: data is available to anyone (don't have access to cron, to delete data from time to time)

  2. render in the browser (has to work on IE)?

  3. Use javascript (Raphaël—JavaScript Library) or Google API and output a PDF report (need plugin or gem, right)?

  4. use send_data? i've tried to output other way than inline, because I needs to show other data, is it possible?

Thanks for any help.

+1  A: 

Although it's annoying, you can always prune off old entries as part of your generation procedure. This is really only something you need to do if you don't have a background job facility of some sort such as cron. Checking based on file "modification time" is usually the best way to go, but this also has the effect of breaking old links to images.

A canvas-based approach is significantly better than server-generated images. For example, using something like Flot to build canvas-based graphs and include explorercanvas where required for IE compatibility.

tadman
A: 

Hi Muralha,

I am currently doing the same thing, and was looking into gruff to do serverside generation of my charts.

I had gruff generate an image in my controller and write the image to my public images directory, and then simply link to the image from my view.

That said, the charts were static images, and I wanted something more dynamic.

So, I ended up using the Highcharts jQuery plugin (http://www.highcharts.com/) to generate my charts on the view side. (Much better!)

I just have my controller pass my array data to the view and let the charts draw client side, it is much better and has all the functionality that my clients are used too from Google without being tied to Google's API and flash.

All a matter of opinion of course! :)

Dustin M.
A: 

I have used gruff and it is really slow and consumes a lor of memmory, If you don't change the chrats so much it is a good idea to use gruff with some caching, you can do page caching or fragment caching http://guides.rubyonrails.org/caching_with_rails.htm, but I would recomend you to use google API, there is a gem to simplify the job, http://rubygems.org/gems/googlecharts. If you need that users download the chart I don't think it is a good idea to use graphael or others to make charts.

Boris Barroso
A: 

Thanks for all the inputs.

I think I 'll use Google Charts straight in the image source tag or through the gem.

Thanks again for all the help.

Muralha