I'm not an experienced programmer, but your suggestion does not make much
sense to me. Wouldn't your effort be better spent on improving the existing
chart method? In that way non-dbi-users can use your method without carrying
around the weight of dbi. And to be honest, I find it rather confusing to
build charts with SQL statements.

I like your qoute at the beginning!


-ren

----- Original Message -----
From: "Dean Arnold" <[EMAIL PROTECTED]>
To: "DBI-users" <[EMAIL PROTECTED]>; "DBI-dev" <[EMAIL PROTECTED]>
Sent: Monday, February 05, 2001 4:42 AM
Subject: DBD::Chart ?


"The more I do DBD, the more DBDs I do."
    - Frank Sinatra (paraphrased)

I'm embarking on another DBD effort and wanted to get
some input from the community.

I've been using the Chart::Plot, and GD::Graph modules
to render charts from database rowsets, but feel like
there's an impedance mismatch between DBI
and the charting packages...so I'm whipping up a
DBD::Chart to try and rectify the situation.

At present, the idea is to use "CREATE TABLE..."
like syntax to establish the graph domain info,
use "INSERT..." syntax to add data points,
and then "SELECT..." syntax to actually render the
graph image, returning the image as a bytestring
from $sth->fetch(). All the various chart types
would be supported (bar, pie, line, scatter, curve),
and the various chart attributes would be supplied
in the WHERE clause of the SELECT, e.g.

Example script to render a piechart 300x350 pixels:

$chartdbh = DBI->connect('dbi:Chart');
$chartdbh->do('CREATE TABLE mychart (value FLOAT, region CHAR(20))');

$dbh = DBI->connect('dbi:Oracle', .etc..);
$sth = $dbh->prepare('SELECT cust_satisfaction, region FROM region_info');
my ($satis, $region);
$sth->bind_cols(\$satis, $region);

$chartsth = $chartdbh->prepare('INSERT INTO mychart VALUES(?, ?)');
$chartsth->bind_param(1, $satis);
$chartsth->bind_param(2, $region);

while ($sth->fetch) { $chartsth->execute; }

$piesth = $chartdbh->prepare('SELECT PIECHART FROM mychart ' .
 'WHERE TITLE='Customer Satisfaction' AND ' .
 'WIDTH = 300 AND HEIGHT = 350');
my $chart;
$piesth->bind_col(1, \$chart);
$piesth->fetch;
#
# now you can save it, or send it back to a browser,
# stick it in a Perl Tk window...whatever
#

Example syntax to render an area-filled linegraph
400x200 pixels:
SELECT LINEGRAPH FROM mygraph
WHERE TITLE='Annual Rainfall' AND
 WIDTH=400 AND HEIGHT=200 AND
 FILL=YES AND POINT='' AND
 X-AXIS='Month' AND Y-AXIS='Inches'
 AND COLOR=blue and SHOWGRID=1

Overlapped graphs could be rendered by
pseudo-joins of subqueries:
SELECT IMAGE FROM
 (SELECT LINEGRAPH FROM raingraph
 WHERE TITLE='Annual Rainfall' AND
 FILL=YES AND POINT='+' AND
 X-AXIS='Month' AND Y-AXIS='Inches'
 AND COLOR=blue) A,
 (SELECT LINEGRAPH FROM tempgraph
 WHERE TITLE='Avg. Temperature' AND
 POINT='circle' AND X-AXIS='Month' AND Y-AXIS='Degrees F'
 AND COLOR=red) B
WHERE WIDTH=400 AND HEIGHT=200 AND SHOWGRID=1

If anyone sees anything wrong with this, or has some
features they'd like to see included, please drop me a line.

Regards,
Dean Arnold


Reply via email to