Ok, here's a Database example - look at
http://so.bi.umist.ac.uk/scripts/bars_db.pl for example output.

--
  Simon Oliver


#!perl
use warnings;
use strict;
use DBI;
use GD::Graph::bars;

my ($driver, $dsn, $uid, $pwd, $attr, $dbh, $sql, $sth);

$driver = 'ODBC';
$dsn = 'Orders';
$uid = ''; $pwd = '';
$attr = { RaiseError => 1 };

eval {
  $sql = 'SELECT Employees.LastName, Count(Orders.OrderID) AS CountOfOrderID
FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID
GROUP BY Employees.LastName';
  $dbh = DBI->connect("dbi:$driver:$dsn", $uid, $pwd, $attr);
  $sth = $dbh->prepare($sql);
  $sth->execute();

  my (@names, @counts);
  while (my $row = $sth->fetch) {
    push @names, $row->[0];
    push @counts, $row->[1];
  }
  $sth->finish();
  $dbh->disconnect();

  my $graph = GD::Graph::bars->new(400, 400);

aph->set( 
        x_label           => 'Employees',
        y_label           => 'Sales',
        title             => 'Sales by Employee',
        x_labels_vertical => 1 ,
  );
  my $gd = $graph->plot( [\@names, \@counts]);
  
  binmode STDOUT;
  print "Content-type: image/x-png\n\n";
  print $gd->png;
};

if ($@) {
  print "Content-type: text/html\n\n";
  print '<H4>', HTML_encode($@), '</H4>';
  exit;
}


# HTML encode a string
sub HTML_encode {
    my $toencode = shift;
    return undef unless defined($toencode);
    $toencode=~s/&/&amp;/g;
    $toencode=~s/\"/&quot;/g;
    $toencode=~s/>/&gt;/g;
    $toencode=~s/</&lt;/g;
    return $toencode;
}



_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to