Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I'm trying to draw a simple graph with GD::graph::lines and am following the exact instruction on the CPAN web-site. Anyway, The error message i get is Can't call method "plot" on an undefined value at plot_graph.pl line 32. but i really can t see the error or how @data is undefined. If anyone can spot the error i would be very happy indeed. cheers!
#!/biol/programs/perl/bin/perl -w use GD::Graph::lines; @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ] ); my $graph = GD::Graph::lines->new(400,400); $graph->set ( x_label => 'values1', y_label => 'values2', title => 'Correlate', ) or die $my_graph->error; my $gd = $my_graph->plot(\@data) or die $my_graph->error; open (IMG, '>file.png') or die $!; binmode IMG; print IMG $gd->png;

Replies are listed 'Best First'.
Re: using GD::graph:lines
by zby (Vicar) on Mar 10, 2003 at 10:57 UTC
    You seem to change the name from $graph to $my_graph in the middle of the program.

    use strict would give you a better error description.

Re: using GD::graph:lines
by Hofmator (Curate) on Mar 10, 2003 at 11:54 UTC
    As zby pointed out, all occurrences of $my_graph should be replaced by $graph.

    But you are right about this being straight out of the doc - these examples should work. So drop the module author a line that this inconsistency gets fixed, he'll be happy about it ...

    -- Hofmator