Hi Graff,

Yeah I butchered the code more than a little as I tried to test it. I simplified it again below. The reason I use @rage (symbolic name for my state of mind haha) is that I am not sure how to put the data from the mysql lookup into the 2d array without first collecting them seperately and then pushing them into the same array. (I deleted that line ---my @data = ( \@dates, \@rage);---accidentally when I last posted).

The data that I get is as follows:

+-------------------+ | Tables_in_pzbg001 | +-------------------+ | 2003_5_10 | | 2003_5_5 | | 2003_5_6 | | 2003_5_7 | | 2003_5_8 | | 2003_5_9 | +-------------------+
and I realise that the way I strip it down is very messy indeed, I'm not the best perl programmer to say the least :(. Any advice would be more than welcome and thanks again for taking the time to help me out.

#!/usr/bin/perl use CGI ':standard'; use GD::Graph::lines; use DBI; use Data::Dumper; $inint = "1"; $result = "sum(octets)"; @dates = `mysqlshow --password=\'xxxxxxx\' pzbg001`; shift @dates; shift @dates; shift @dates; shift @dates; pop @dates; foreach $date(@dates){ chomp $date; $date =~ s/ //g; $date =~ s/\|//g; $date =~ s/\-//g; $date =~ s/Tables//g; $date =~ s/\+//g; # Connect to the database. my $dbh = DBI->connect('DBI:mysql:pzbg001', 'root', 'xxxxxxx', {RaiseE +rror => 1}); $query = "select " . "$result " . "from " . "$date " . "where" . " inintf = '$inint'"; $sth = $dbh->prepare($query); if (!$sth) { die "Illegal query: $query" }; $sth ->execute; while (my @row = $sth->fetchrow_array) { foreach $row(@row){ chomp $row; $total = sprintf "%0.f", $row/1024/1024; $total += 0; push (@rage, $total); } } $sth->finish; } my @data = ( \@dates, \@rage); my $mygraph = GD::Graph::lines->new(600, 300); $mygraph->set( x_label => 'Date', y_label => 'Kb of Traffic', title => 'Traffic for $router ', # Draw datasets in 'solid', 'dashed' and 'dotted-dashed' lines line_types => [1], # Set the thickness of line line_width => 2, # Set colors for datasets dclrs => ['blue'], ) or warn $mygraph->error; $mygraph->set_legend_font(GD::gdMediumBoldFont); $mygraph->set_legend('Total'); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; print "Content-type: image/png\n\n"; print $myimage->png; __END__

Baiul

Ubi Concordia Ibi Victoria


In reply to Re: Re: GD::Graph::lines problem! by Baiul
in thread GD::Graph::lines problem! by Baiul

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.