Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Curious issue with Graphing Arrays

by Errto (Vicar)
on Nov 13, 2007 at 20:34 UTC ( [id://650589]=note: print w/replies, xml ) Need Help??


in reply to Curious issue with Graphing Arrays

It looks like this isn't a GD::Graph issue but rather a referencing issue. Specifically, the way you're assigning your arrays is wrong. It should be either:
@name1 = (6, 18, 21, 28, 36, 44, 52, 67, 78, 89); @name2 = (1, 15, 22, 31, 45, 7, 19, 21, 36, 41); @name3 = (8, 91, 78, 88, 87, 80, 96, 95, 99, 99); @xaxis = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
or else
$name1 = [6, 18, 21, 28, 36, 44, 52, 67, 78, 89]; $name2 = [1, 15, 22, 31, 45, 7, 19, 21, 36, 41]; $name3 = [8, 91, 78, 88, 87, 80, 96, 95, 99, 99]; $xaxis = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
In the latter case, you would change the @data assignment to
@data = ( $xaxis, $name1, $name2, $name3 );
The reason is that with your current code, you're actually creating three one-element arrays, each containing an array reference as its first element. Also, if you do go with the first approach, no need to duplicate the contents of the arrays. Just do
@data = ( \@xaxis, \@name1, \@name2, \@name3 );

Replies are listed 'Best First'.
Re^2: Curious issue with Graphing Arrays
by SoaponaRope (Novice) on Nov 13, 2007 at 20:49 UTC
    Thanks for the help, that certainly fixed the issue.

    The next issue that I have is in attempting to name the variable dynamically, using a counter. So, instead of coding @name1, @name2 etc, we'd instead code something like this:

    $x = 1; @name[$x] = (stuff); $x++
    This would loop through several times to assign outputs from dynamic SQL statements to the dynamically named arrays, which are then output to a graph. Any idea on what the syntax would be to name that?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://650589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found