How to integrate Scruff Images

Hi Folks,

since I have scruffy up and running now I´d like to integrate the
desired images on some of my rails views. But neither scruffy nor rails
docs say something about this and I cannot find examples or help on
this. So I hope somebody on this forum has experiences in integrating
scruffy images on rails views.

I find out how to go the easy and obvious way: Export image to a file
and then bind the exported file on the view template. But I wonder if I
cannot get scruffy images directly on my rails pages without exporting
it to disk first.

My approach with a simple example from Brastens page:
I created this method in my views helper class:
def generate_img()
graph = Scruffy::Graph.new

graph.title = "Comparative Agent Performance"
graph.value_formatter = 

Scruffy::Formatters::Percentage.new(:precision => 0)

graph.add :stacked do |stacked|
  stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
  stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
  stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
end

graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']

graph.render(:width => 800, :as => 'JPG')

end

And in my views rhtml page I put this:
<%= generate_img %>

Unfortunately it display rubbish instead of the expected image.

The encapsulation with the tag is also not working.

Can anyone point me to the right direction?

Thanks & Regards,

Christian

Doh! Mixed up the name in the headline: Must be “Scruffy” not “Scruff”.
Sorry!

Okay I figured it out myself, should have had a closer look on this
forum before :wink:

Here we go:
In my controller I added this method:
def show_img
graph = Scruffy::Graph.new

graph.title = "Comparative Agent Performance"
graph.value_formatter = 

Scruffy::Formatters::Percentage.new(:precision => 0)

graph.add :stacked do |stacked|
  stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
  stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
  stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
end

graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']

send_data(graph.render(:width => 800, :as => 'PNG'), :type => 

‘image/png’, :disposition=> ‘inline’)
end

And in the views rhtml file I added this:

And now it works!

Regards,

Chris

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