Graphs and Plots in Rails

You guys need to check my site and let me know if you like any of those
graphs

http://jackster.mobi

Chris Mccauley wrote:

Why not use the Google Chart API?

http://code.google.com/apis/chart/

Nice, I like the Google Charts. I think I'll try this, along with
Scruff...if I can ever get RMagick running :slight_smile:

Thanks everyone for your inputs!

One last question to get me running...

I tried testing this after I installed the plugin...

In view and then controller and nothing rendered? I also restarted
the server...

GoogleChart.pie(10,20,40,30).to_url

What did I miss here?

You left all this info (see bellow) intentionally?

Cheers, Sazima

params | session | env | request

I'm guessing that you need:

<%= image_tag GoogleChart.pie(10,20,40,30).to_url %>

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

I don't think I understand what you mean?

Interesting, it looks like if I use image_tag, it creates a blank
space where the chart should be, but there is nothing there?

pete wrote:

One last question to get me running...

I tried testing this after I installed the plugin...

In view and then controller and nothing rendered? I also restarted
the server...

GoogleChart.pie(10,20,40,30).to_url

What did I miss here?

I found the same issue when testing Google Charts on Rails, which is why
I liked GoogleCharts better.

What does the page source look like? Does the URL for the image src look OK? Does it need to have &'s escaped to &amp;'s?

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com

<img alt="Chart?chs=200x200&amp;cht=p&amp;chd=t:10,20,40,30"
src="http://chart.apis.google.com/chart?
chs=200x200&amp;cht=p&amp;chd=t:10,20,40,30.png" />

Looks like it needs to be escaped?

Ah! You're on Rails 1.2.x, right? See that '.png' at the end, you
don't want that. Unless you actually depend on rails tacking that on
for you, go to vendor/rails/actionpack/lib/action_view/helpers/
asset_tag_helper.rb and change image_path to be:

       def image_path(source)
         # unless (source.split("/").last || source).include?
(".") || source.blank?
         # ActiveSupport::Deprecation.warn(
         # "You've called image_path with a source that
doesn't include an extension. " +
         # "In Rails 2.0, that will not result in .png
automatically being appended. " +
         # "So you should call image_path('#{source}.png')
instead", caller
         # )
         # end

         compute_public_path(source, 'images')
       end

and all should be OK. (the &'s are already escaped)

You probably also want to provide your own :alt => "description of the
chart" so it makes sense if Google doesn't return an image (or just
takes a while).

-Rob

Yes, I am...should I upgrade?

If I modify the asset_tag_helper, would this have any negative affect
on anything else?

Ok, I commented out the warning and restarted the server...still no
image.

And I missed updating the compute_public_path(source, 'images') line,
now that is up-to-date and I get an error ("wrong number of arguments
(2 for 3)") for this:

<%= image_path GoogleChart.pie(10,20,40,30).to_url %>
or also tried...
<%= image_tag GoogleChart.pie(10,20,40,30).to_url %>

You can also just use the api without the rails plugin, it'n not very
complicated.

Update? Not necessarily (and certainly not just for this!), I still
have clients on 1.1.6 and none of my clients are on Rails 2.x yet.

Try these:

<a href="<%= GoogleChart.pie(10,20,40,30).to_url %>">link to chart</a>
<img src="<%= GoogleChart.pie(10,20,40,30).to_url %>" alt="Google pie
chart" />

which should be what you'd get from:
<%= link_to 'link to chart', GoogleChart.pie(10,20,40,30).to_url %>
<%= image_tag GoogleChart.pie(10,20,40,30).to_url, :alt => "Google pie
chart" %>

You could even add the 200x200 size, but that's a frivolous detail
until it works.

The URL works when I paste it into a browser so it should be working.

-Rob

Hi pete,

First of all, I believe you might be using an old or outdated version
of the GoogleCharts plugin because you are using GoogleChart.pie
rather than Gchart.pie. You can get the latest version from this site:

A Google Chart URL should like this once generated (there is no .png
extension):
<img src="http://chart.apis.google.com/chart?
cht=lc&chs=200x125&chd=s:helloWorld&chxt=x,y&chxl=0:|Mar|Apr|May|June|
July>1:||50+Kb" title="Custom" alt="Custom" />

If possible, I would just recommend upgrading to a newer Rails. I
think Rob is right and Rails is automatically appending the .png
extension thereby breaking the url. You can test this by not using
image_tag:

<img src="<%= Gchart.pie(:data => [20, 35, 45]) %>" />

Jason

I have used Gruff with great success, and being Ruby, it is also very
easy to extend. For prettier graphs, and a much more compelete graphing
library, I use JRuby with JFreeChart. Works very well and compares very
well to Gruff speedwise.

Uwe

can you post a link to some examples?

thanks

jackster

Uwe Kubosch wrote: