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