in reply to GD Graph Question
I'm going to make a few suggestions to you. You are not constructing your array in the way GD::Graph expects, but there are some other things that I hope you'll listen to.
The first is to make sure you use strict; That will tell you if this is failing for some silly reason like having mis-typed "data". It's going to force you to go back and make sure all of your variables are initialized with my but that's a good thing.
OK, now with that out of the way, let's see what is wrong with your @data array. If you check the documentation for GD::Graph you'll see that the plot method requires that your data be sent as a list of anonymous arrays. Doing a my @data = (@a, @b); has the effect of concatinating the arrays together. What you actually want to do is construct a list of array references like this: my @data = (\@a, \@b);
To see why this does what you want and why your print test should have clued you into this see my sample code at the end.
One more nit to pick first though! You are mixing functional calls and methods in your code. Don't do that! It's confusing and my not even work with all modules (like the crappy ones I write! :) ). If you like methods be consistent and say my $graph = GD::Graph::lines3d->new(600,400); or whatever the format is. It may not be a big deal in the big scheme of things, but consistency always pays off for a programmer.
Good luck and check out my demo code at the end for clarification,
{NULE}
--
http://www.nule.org
#! /usr/bin/perl -w use strict; my @a=(1,2,3,4); my @b=(5,6,7,8); my @c=(@a, @b); my @d=([1,2,3,4],[5,6,7,8]); my @e=(\@a, \@b); print "constructed with (\@a, \@b)\n"; foreach (@c) { print "$_\t"; } print "\nexplicit ([list],[list])\n"; foreach (@d) { print "$_\t"; } print "\nfinally (\\\@a, \\\@b)\n"; foreach (@e) { print "$_\t"; }
|
|---|