# Ruport GraphReport

**URL:** <https://www.ruby-forum.com/t/ruport-graphreport/112196>\
**Category:** Ruby\
**Created:** [August 16, 2007, 8:21am UTC](https://www.ruby-forum.com/t/ruport-graphreport/112196 "2007-08-16T08:21:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [August 16, 2007, 8:21am UTC](https://www.ruby-forum.com/t/ruport-graphreport/112196/1 "2007-08-16T08:21:06Z")

</div>

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 method`generate’ 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:in`old\_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:in`build’  
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:in`old\_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:in`save\_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:in`save\_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. ☹

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [August 16, 2007, 9:41am UTC](https://www.ruby-forum.com/t/ruport-graphreport/112196/2 "2007-08-16T09:41:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [August 17, 2007, 1:54am UTC](https://www.ruby-forum.com/t/ruport-graphreport/112196/3 "2007-08-17T01:54:53Z")

</div>

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?
