Update: ishnid's right, the data needs to be grouped by axis, not by point. In his answer, he did miss the bit about your push needing the same unless as your split.
The data needs to be organized into a 2d array. Try changing
push @array, ($x, $y);
to
push @array, [$x, $y];
push @{$array[0]}, $x;
push @{$array[1]}, $y;
Also, I think the first row of the array need to be labels. I'd try adding
@array = (['RT', 'HEIGHT']);
before the while.
You're unless /RT/ needs to be extended to the push.
I'm really just guessing from a glance at the docs. I don't have any experince this module.
open (FH, "<data.txt"); while (<FH>) { chomp; next if /RT/; ($x, $y) = split(/\s+/, $_); push @{$array[0]}, $x; push @{$array[1]}, $y; } my $mygraph = GD::Graph::lines->new(600, 300); $mygraph->set( x_label => 'RT', y_label => 'HEIGHT', title => 'xxx' ); $image = $mygraph->plot(\@array) or die $mygraph->error; open(IMG, '>file2.png') or die $!; binmode IMG; print IMG $image->png; close IMG;
In reply to Re: line graph GD::GRAPH
by ikegami
in thread line graph GD::GRAPH
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |