GD::Graph question
Ovid
publiustemp-londonpm at yahoo.com
Sun Nov 12 16:49:16 GMT 2006
--- Adrian McMenamin <adrian at newgolddream.dyndns.info> wrote:
> Apologies if this sort of question isn't appropriate to the list -
> it's hard to tell from the archives.
>
> I have used GD::Graph::pie without problems but I cannot get it to
> draw a line graph.
There are appear to be a few issues with your code, not the least of
which is that it looks like you may not be using strict. For a working
example of GD::Graph::lines, I created a graph comparing Bush and
Blair's popularity at
http://publius-ovidius.livejournal.com/202197.html
Specific problems with your code:
> $graph->set(title => $formdata{"title"},
> label => $formdata{"label"},
> x_label => "X",
> y_label => "Y",
> );
There is no attribute 'label', according to the GD::Graph docs (and the
error message I generated. I see someone else responded to this and
they used 'label', so I could be wrong.
> @data = (["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
> "12",
> "13", "14", "15", "16", "17", "18", "19", "20"], [$votes[0],
> $votes[1],
> $votes[2], $votes[3], $votes[4], $votes[5], $votes[6], $votes[7],
> $votes[8], $votes[9], $votes[10], $votes[11], $votes[12], $votes[13],
> $votes[14], $votes[15], $votes[16], $votes[17], $votes[18],
> $votes[19] ]);
This is better written as:
my @data = (
[ 1 .. 20 ],
\@votes
);
If you have more than 20 records in @votes, then you want an array
slice:
[ @votes[ 0 .. 19 ] ]
> [Sat Nov 11 20:57:23 2006] [error] [client 81.1.88.190] Can't call
> method "png" on an undefined value
> at /usr/lib/cgi-bin/hatetories/scoregraph.pl line 87.
You're getting that error because of this:
> print $graph->plot(\@data)->png or die $graph_error;
$graph_error should be $graph->error. However, that should be two
statements:
my $gd = $graph->plot( \@data ) or die $graph->error;
print $gd->png;
The 'Can't call method "png" on an undefined value' is because
$graph->plot is returning an undefined value.
Hope that helps.
Cheers,
Ovid
--
Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
More information about the london.pm
mailing list