Mailinglist Archive: opensuse (3261 mails)
| < Previous | Next > |
How to generate perl graph from database?
- From: Alex Daniloff <alex@xxxxxxxxxxxx>
- Date: Mon, 9 Apr 2001 20:57:14 -0700
- Message-id: <01040920571400.05756@gate>
Hello Linux folkz,
Finally I'm able to retrieve needed data from M$SQL database with perl but I
need to draw a graph from this data as well. After long hours of hair pulling
I still couldn't figure out how to pass an array of retrieved parameters into
the form of graph. Could somebody please take a look at the attached script
and correct me what I'm doing wrong.
Thank you in advance.
Alex
#!/usr/bin/perl -wT
use CGI;
use DBI;
use GD::Graph::mixed;
use CGI::Carp qw(fatalsToBrowser); # Shows all errors in the Web Page
my $q = new CGI;
my $graph = new GD::Graph::mixed(400, 600);
$graph->set(
title => TITLE,
x_label => "Wafer Parameter",
y_label => "Values",
long_ticks => 1,
bar_spacing => 2,
types => ["bars", "linespoints"],
);
$graph->set_legend("Wafer", "Yield");
# Definitions
$data_source = "dbi:Sybase:mds_test:server=prdserv3";
$user = "myid";
$password = "mypassword";
$dbh = DBI->connect($data_source, $user, $password, {PrintError => 0})
|| die "Database connection failed: $DBI::errstr";
$SQL = "select * from prms where grp='6BB50' and spec='T' and type='M'";
$sth = $dbh->prepare($SQL);
$sth->execute();
if ($sth->err) {die "Error ", $sth->err;}
while(@row = $sth->fetchrow_array) {
foreach $field(@row)
{ my @data = @row; }
}
my $image = $graph->plot( \@data);
print $q->header( -type => "image/png");
print $image->png;
--
MS Windows users should be covered under the Americans with Disabilities Act!
--------------> Try Linux and you'll understand why <--------------
Finally I'm able to retrieve needed data from M$SQL database with perl but I
need to draw a graph from this data as well. After long hours of hair pulling
I still couldn't figure out how to pass an array of retrieved parameters into
the form of graph. Could somebody please take a look at the attached script
and correct me what I'm doing wrong.
Thank you in advance.
Alex
#!/usr/bin/perl -wT
use CGI;
use DBI;
use GD::Graph::mixed;
use CGI::Carp qw(fatalsToBrowser); # Shows all errors in the Web Page
my $q = new CGI;
my $graph = new GD::Graph::mixed(400, 600);
$graph->set(
title => TITLE,
x_label => "Wafer Parameter",
y_label => "Values",
long_ticks => 1,
bar_spacing => 2,
types => ["bars", "linespoints"],
);
$graph->set_legend("Wafer", "Yield");
# Definitions
$data_source = "dbi:Sybase:mds_test:server=prdserv3";
$user = "myid";
$password = "mypassword";
$dbh = DBI->connect($data_source, $user, $password, {PrintError => 0})
|| die "Database connection failed: $DBI::errstr";
$SQL = "select * from prms where grp='6BB50' and spec='T' and type='M'";
$sth = $dbh->prepare($SQL);
$sth->execute();
if ($sth->err) {die "Error ", $sth->err;}
while(@row = $sth->fetchrow_array) {
foreach $field(@row)
{ my @data = @row; }
}
my $image = $graph->plot( \@data);
print $q->header( -type => "image/png");
print $image->png;
--
MS Windows users should be covered under the Americans with Disabilities Act!
--------------> Try Linux and you'll understand why <--------------
| < Previous | Next > |