[root@sauron netflow]# /var/www/cgi-bin/testgraphtotal.cgi $VAR1 = [ [ '2003_5_10', '2003_5_5', '2003_5_6', '2003_5_7', '2003_5_8', '2003_5_9' ], [ 1667, 912, 151, 1055, 2043, 2663 ] ]; $VAR1 = [ [ '2003_5_10', '2003_5_5', '2003_5_6', '2003_5_7', '2003_5_8', '2003_5_9' ], [ 1667, 912, 151, 1055, 2043, 2663 ] ]; #### #!/usr/bin/perl use CGI ':standard'; use GD::Graph::lines; use DBI; use Data::Dumper; #use strict; #######@routers = ('lric015','pzbg001'); #######foreach $router(@routers){ $inint = "1"; $result = "sum(octets)"; @dates = `mysqlshow --password=\'xxxxxxx\' pzbg001`; shift @dates; shift @dates; shift @dates; shift @dates; pop @dates; #@dates = `mysqlshow --password=\'xxxxxxx\' pzbg001`; foreach $date(@dates){ chomp $date; $date =~ s/ //g; $date =~ s/\|//g; $date =~ s/\-//g; $date =~ s/Tables//g; $date =~ s/\+//g; #print $date; #} #$date = "2003_5_9"; # Connect to the database. my $dbh = DBI->connect('DBI:mysql:pzbg001', 'root', 'xxxxxxx', {RaiseError => 1}); $query = "select " . "$result " . "from " . "$date " . "where" . " inintf = '$inint'"; # . "from " . "2003_5_9 " . "where" . " inintf = '$inint'"; #print $query; $sth = $dbh->prepare($query); if (!$sth) { die "Illegal query: $query" }; $sth ->execute; while (my @row = $sth->fetchrow_array) { # print "@row\n"; ####### ####### foreach $row(@row){ chomp $row; $total = sprintf "%0.f", $row/1024/1024; #$total = sprintf "%0.f", $row/1024; $total += 0; push (@rage, $total); #my @row = $sth->fetchrow_array; } } $sth->finish; } #my @test1 = ('2003_5_10', '2003_5_5', '2003_5_6', '2003_5_7', '2003_5_8', '2003_5_9'); #my @test2 = (1667, 912, 151, 1055, 2043, 2663); #my @data = ( \@dates, \@test2); #my @data = ( \@test1, \@rage); #my @data = ( \@test1, \@test2); #print Dumper( \@data);# #print "@data\n"; #my @data = (['2003_5_10', '2003_5_5', '2003_5_6', '2003_5_7', '2003_5_8', '2003_5_9' ], #[1667, 912, 151, 1055, 2043, 2663]); 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, 2, 4], line_types => [1], # Set the thickness of line line_width => 2, # Set colors for datasets #dclrs => ['blue', 'green', 'cyan'], #dclrs => ['blue', 'green', 'cyan'], dclrs => ['blue'], ) or warn $mygraph->error; $mygraph->set_legend_font(GD::gdMediumBoldFont); #$mygraph->set_legend('Total', 'Exam 2', 'Exam 3'); $mygraph->set_legend('Total'); my $myimage = $mygraph->plot(\@data) or die $mygraph->error; print "Content-type: image/png\n\n"; print $myimage->png; __END__