This code gives me a result:

use strict; use warnings; use GD::Graph::bars; my @data; my $graph = GD::Graph::bars->new( 400, 300 ); for ( my $x=1; $x<10; $x++) { my @anotherarray=(1,2,3,4,5); push @data, [ @anotherarray ]; } my $gd = $graph->plot(\@data) or die $graph->error; open ( my $img, '>file.png') or die $!; binmode $img; print $img $gd->png; close $img;

The result is five groupings of 8 (not 9, check your loop counter) lines each in a vertical bar chart in a PNG file.

I'm not sure which portions are different from your entire program, because you provided only a particular portion. That portion may not be the one at fault after all. Be sure to post small yet functional code snippets for the best results. Also, I made what changes were necessary to use the strict and warnings pragmas. That's always a good idea.

Now that you've seen a working example using your own data structure, you should be able to start comparing things to figure out what else could be wrong.


In reply to Re: GD @data array question by mr_mischief
in thread GD @data array question by andy_7t

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.