Graphs and Plots in Rails

I’m guessing that you need:

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

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

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?

On Jan 30, 6:58 pm, Rob B. [email protected]

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 %>

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

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

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):
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:

Jason

On Tue, 2008-01-29 at 08:09 -0800, pete wrote:

I did a search and found some old posts on the subject, however since
these things change so rapidly, I’m wondering what the best options
are for creating charts and plots in a Rails app?

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

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:

link to chart
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

can you post a link to some examples?

thanks

jackster

Uwe K. wrote:

On Tue, 2008-01-29 at 08:09 -0800, pete wrote:

I did a search and found some old posts on the subject, however since
these things change so rapidly, I’m wondering what the best options
are for creating charts and plots in a Rails app?

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs