Helpful Information
 
 
Category: Ruby & Ruby On Rails
Gruff graphs problem

This was a previous class assignment, and I decided I wanted to make the graph look slightly better so I decided to place a min/max value and set the increment for the graph up as well. Here is the function that creates the graph:


def update_graph
$g = Gruff::Line.new(600)
$g.title = "Name Popularity In Census Years"
#add data to graph
$list.each do
|name|
$g.data(name.upcase,$hash[name.upcase])
end

#labels for graph, census years 1900-2000
$g.labels = {0 => '1900',1 => '10',2 => '20',3 => '30',4 => '40',
5 => '50',6 => '60',7 => '70',8 => '80',9 => '90',10 => '2000'}

#configure graph appearance
$g.minimum_value= 0
$g.maximum_value= 1000
$g.y_axis_label= "Name Rank"
$g.x_axis_label= "Census Year"

#***WHY DOESNT THIS WORK?!?!?!?***
$g.y_axis_increment= 100

$g.write('graph.gif') #create graph file

#update the output to show the graph
$output_label.configure(:image => TkPhotoImage.new(:file => "graph.gif"))

$entry_field.value = nil #clear entry field

`rm graph.gif` #remove the graph file
end

My problem is, when I use g.y_axis_increment= 100, the graph will not draw and gives the error "ArgumentError, wrong number of arguments (1 for 0)" and it points to this line:

$g.write('graph.gif') #create graph file

This would normally suggest that the write function shouldnt take an argument, however, when I comment the g.y_axis_increment= 100, the program runs flawlessly. Anyone have a clue why this line would break the write function?

g.write ----- g cant be used because .write isnt a method that pretains to the object of g....write is used to write the given string to [I]IO[I]

an example of write would be this :

number = STDOUT.write( "whatever text\n")
puts "Just wrote #{number} bytes to the screen"










privacy (GDPR)