GD::Graph question
Phil Pennock
phil.pennock at globnix.org
Sun Nov 12 16:00:45 GMT 2006
On 2006-11-11 at 20:58 +0000, Adrian McMenamin wrote:
> I have used GD::Graph::pie without problems but I cannot get it to draw
> a line graph.
You have undefined data somewhere?
It's a bit hard to tell, since your example snippet refers to data you
don't define for us.
Filling in the blanks a bit, munging to get it to pass "perl -c", using
$graph->error instead of $graph_error, the below script works for me.
Does this help?
-----------------------------< cut here >-------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use GD;
use GD::Graph;
use GD::Graph::lines;
my @pixel_dimensions = (800, 700);
my ($xrange, $yrange) = (20, 50);
my %formdata = (
title => "Test",
label => "charted",
);
my @votes;
for (my $i = 0; $i < $xrange; ++$i) {
$votes[$i] = int(rand($yrange));
}
print "Content-type: image/png\r\n\r\n";
# $GD::Graph::Error::Debug = 5;
my $graph = GD::Graph::lines->new(@pixel_dimensions);
$graph->set(title => $formdata{"title"},
label => $formdata{"label"},
x_label => "X",
y_label => "Y",
y_max_value => $yrange,
);
my @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] ]);
$graph->set_title_font(gdLargeFont, 18);
print $graph->plot(\@data)->png or die $graph->error;
exit(0);
__END__
More information about the london.pm
mailing list