Ruport GraphReport

this is rather a followup from my other post…in the attempt to try and
graph a quick sample data i get richeous errors lol.

require ‘rubygems’
require ‘ruport’
require ‘ruport/util’
require ‘tempfile’

class GraphReport < Ruport::Report

    renders_as_graph

isp1r = []
isp1 = Tempfile.new(‘tempisp’)
isp1.puts File.readlines(‘maindata.csv’).grep(/Blah1/)
isp1.each do |row|
isp1r << row[“AVERAGE”]
isp1.close

def generate
graph = Ruport::Graph(:column_names =>
%w[24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0])
graph.add_line [isp1r], :name => “Blah1”
graph.add_line [14,54,22,54,12], :name => “bar” # Just an extra line,no
reason
return graph
end
end
end

puts GraphReport.generate{|r| r.save_as(“filename.svg”)}

theoretically this should have generated 2 lines, 0 - 24 on the bottom
of the graph, and the Blah1 grep data up the side.

instead i get some awesome errors

ruby ruporttest.rb
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:115:in
method_missing': undefined local variable or methodgenerate’ for
#GraphReport:0xb7805a7c (NameError)
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:86:in
renderable_data' from /var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:171:inold_as’
from
/var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:383:in
render' from /var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:428:inbuild’
from
/var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:382:in
render' from /var/lib/gems/1.8/gems/ruport-1.0.1/lib/ruport/renderer.rb:169:inold_as’
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:93:in
as' from /var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:107:insave_as’
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:107:in
open' from /var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:107:insave_as’
from ruporttest.rb:26
from
/var/lib/gems/1.8/gems/ruport-util-0.7.2/lib/ruport/util/report.rb:124:in
`generate’
from ruporttest.rb:26

shrug i cant even fathom where to begin. :frowning:

On 16 Aug 2007, at 15:21, Michael L. wrote:

graph = Ruport::Graph(:column_names =>
puts GraphReport.generate{|r| r.save_as(“filename.svg”)}

theoretically this should have generated 2 lines, 0 - 24 on the bottom
of the graph, and the Blah1 grep data up the side.

instead i get some awesome errors

No offence, but there are a lot of problems with the script you
posted! Check your do/end pairs and your usage of tempfile. I still
don’t think you need a temporary file though, because Ruport/
FasterCSV can parse from a string.

Using this csv file:

Name,Average
Bill,2
Bob,1
Blah1,10
Jill,3
Jane,4
Blah1,20
Ada,6
Blah1,30
Ruby,7
Blah1,40
Sigfried,2
Blah1,50

Does this code help?:

require ‘rubygems’
require ‘ruport’
require ‘ruport/util’
require ‘tempfile’

class GraphReport < Ruport::Report

renders_as_graph

def generate

 data = File.readlines('filename.csv') #Read in csv (into Array)
 head = data[0] #Take header line
 data = data.grep(/Blah/) #Grep out lines we are interested in
 csv  = ([head] + data).join #Combine the header and lines back

into a String

 table = Ruport::Data::Table.parse(csv) #Parse into ruport

 graph = Ruport::Graph() #Plot
 graph.add_line table.column('Average').map{|x|x.to_i}, :name =>

“Blah1”
graph.add_line [14,54,22,54,12], :name => “bar” # Just an extra
line,no
return graph
end
end

puts GraphReport.generate{|r| r.save_as(“filename.svg”)}

Alex G.

Bioinformatics Center
Kyoto University

lol alright that worked out pretty nicely, but how would i align the 24

  • 0 with the Times that Blah1 is set at:
    EX:

Time–Average–Name
14:21 3.42 Blah1
13:45 2.12 Blah1

so i need to align 14:21 with 14.21 on the graph

n-e ideas?