in reply to Re: Re: Re: GD::Graph::lines problem!
in thread GD::Graph::lines problem!

First off thanks for the help!

Second, I found a way around the initial way I was getting the values of table names as follows

@dates = $dbh->ListTables;

This brings out the data without problem but makes no difference to the end result.

In regards to me doing the wrong thing with

@data = [\@dates, \@rage]

I thought this myself, but when I type in the data for two arrays and then add them in the same fashion as show above it works. Only if the original data comes from Mysql do I seem to have a problem, be it tablename or results from the query.

I'm going to try the rest of the script as you have it and let you know how it went.

Thanks again,
Baiul.

Ubi Concordia Ibi Victoria

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: GD::Graph::lines problem!
by Baiul (Acolyte) on May 11, 2003 at 11:04 UTC
    Tonight I will at last sleep well! Your code failed and my code failed but a hybrid of the two works perfectly! Ubi Concordia Ibi Victoria indeed! The code below works without problem and prints out the graph that I am ever so happy to see!

    Thank you so much again for your help! Code as follows:

    #!/usr/bin/perl use CGI ':standard'; use GD::Graph::lines; use DBI; use Data::Dumper; use Mysql; $inint = "1"; $result = "sum(octets)"; my $dbh = Mysql->connect('localhost','pzbg001','root','xxxxxxx'); @dates = $dbh->ListTables; # query each table for sum of traffic, # push table_name (i.e. date) and traffic sum onto @data: my @data = (); for my $date ( @dates ) { my $dbh = DBI->connect('DBI:mysql:pzbg001', 'root', 'xxxxxxx', {Ra +iseError => 1}); my $query = "select $result from $date where inintf=$inint"; my $sth = $dbh->prepare($query); if (!$sth) { die "Illegal query: $query" }; $sth->execute; my $octets = ($sth->fetchrow_array)[0]; # don't chomp it! $sth->finish; push (@total, $octets/(1024*1024)); } my @data = ( \@dates, \@total); ##################### 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;

    Baiul

    Ubi Concordia Ibi Victoria