Hi liquidc00l,

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"; }

In reply to Re: GD Graph Question by {NULE}
in thread GD Graph Question by liquidc00l

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.