Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts

    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:

    Code:
    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:
    Code:
    $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?

  • #2
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •