Wednesday, October 28, 2009

Easy Grpahs with Scruffy on RoR

Scruffy Library
Scruffy Examples

1 Install scruffy gem
gem install scruffy

2 Prerequisites for scruffy gem.. (RMagick,ImageMagick)

So download from http://rubyforge.org/frs/download.php/38052/RMagick-2.5.0-ImageMagick-6.4.1-5-Q8.zip

i) Extract this to temperory folder.

ii) Run the ImageMagick installer

iii) Install RMagick gem

3) After this try samples from

Scruffy Examples

Started to work, Except it shown in examples
I face same problem while i was trying

One blog post which helped me to fix this was
http://www.ruby-forum.com/topic/193988%20

It suggests to replace the line 35, of the base.rb (for me it is C:\Ruby\lib\ruby\gems\1.8\gems\scruffy-0.2.6\lib\scruffy\renderers\base.rb)with

svg.svg(:xmlns => "http://www.w3.org/2000/svg", 'xmlns:xlink' =>"http://www.w3.org/1999/xlink",:viewBox => "0 0 #{options[:size].first} #{options[:size].last}") {


4) Now You can see same graps as shown examples.

Example:

Controllers Code
....

app/graphs_controller


def index

@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, 'Siva', [30, 60, 49, 29, 100, 120]
stacked.add :bar, 'Krishna', [120, 240, 0, 100, 140, 20]
stacked.add :bar, 'Motamarri', [10, 10, 90, 20, 40, 10]
end
@graph.point_markers = ['Jan', 'Feb','Mar','Apr', 'May', 'Jun','Jul']

@graph.render(:width => 800, :as => 'JPG',:to => "#{RAILS_ROOT}/public/images/AgentGraph.jpg")
# (stores the image in "/public/images" folder in ".jpg" format)

end


Display Graphs in view page
"app/views/graphs/index.html.erb"

<%= image_tag("
AgentGraph.jpg %>")


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.