GD::Graph question

J

Johh

Hello, the following piece of code keeps telling me that i can't plot
using undefined values but as far as i can tell they are all defined.
Sorry if i'm being stupid but can someone help i could do with getting
the graph module working. Thanks in advance.


#!/usr/local/bin/perl
@1 = (1,2);
@2 = (2,1);

#makes the arrray of array for the graph
@data = (@1, @2);


#drawing graphs test
use GD::Graph::points;

$graph = GD::Graph::points->new(400, 300);

$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Graph Master',
y_max_value => 100,
y_tick_number => 8,
y_label_skip => 2
) or die $my_graph->error;

$gd = $my_graph->plot(\@data) or die $my_graph->error;

open(IMG, '>graph.gif') or die $!;
binmode IMG;
print IMG $gd->png;
 
A

A. Sinan Unur

Hello, the following piece of code keeps telling me that i can't plot
using undefined values but as far as i can tell they are all defined.

Please read the posting guidelines for this group to find out how you
can help yourself, and help others help you.
#!/usr/local/bin/perl

use strict;
use warnings;
@1 = (1,2);
@2 = (2,1);

perldoc perldata:

Variable names
....
Usually this name is a single *identifier*, that is, a string
beginning with a letter or underscore, and containing letters,
underscores, and digits.
....

my @x_data = (1, 2);
my @y_data = (2, 1);
#makes the arrray of array for the graph
@data = (@1, @2);

No. You need to call the plot method with a reference to an array of
references. So:

my @data = (\@x_data, \@y_data);
#drawing graphs test
use GD::Graph::points;

$graph = GD::Graph::points->new(400, 300);

my $graph = GD::Graph::points->new(400, 300);
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Graph Master',
y_max_value => 100,
y_tick_number => 8,
y_label_skip => 2
) or die $my_graph->error;

or die $graph->error;

You have no variable called $my_graph.
$gd = $my_graph->plot(\@data) or die $my_graph->error;

my $gd = $graph->plot(\@data)
or die $graph->error;
open(IMG, '>graph.gif') or die $!;

open my $img, '>', 'graph.gif'
or die $!';
binmode IMG;

binmode $img;
print IMG $gd->png;

print $img $gd->png;

__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,441
Members
47,125
Latest member
MDBT

Latest Threads

Top