Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Curious issue with Graphing Arrays

by Errto (Vicar)
on Nov 13, 2007 at 20:34 UTC ( #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 );


Comment on Re: Curious issue with Graphing Arrays
Select or Download Code
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
Node Status?
node history
Node Type: note [id://650589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-09-23 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls