Hi list,

I tried to produce a 3D barchart with DBD::Chart thanks to this code
sample (source: Perl for Oracle DBAs, ORA):

--snip--
use DBI;
use strict;
my $dbh= DBI->connect('dbi:Chart:', undef, undef, { PrintError => 1,
RaiseError => 1 });

$dbh->do('CREATE TABLE spiritaxis (
        Month char(3),
        Visitors integer,
        Monument varchar(11))');

my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my @monuments = qw(Stonehenge Avebury SilburyHill Glastonbury
WhiteHorse);

my $sth = $dbh->prepare('INSERT INTO spiritaxis VALUES(?, ?, ?)');

foreach my $month (@months) {
        foreach my $visitors (@monuments) {
              $sth->execute($month, 1 * int(rand(2000)), $visitors);
        }
}

$sth = $dbh->prepare(
   "SELECT BARCHART, IMAGEMAP
      FROM spiritaxis
     WHERE WIDTH=1000 AND HEIGHT=600 AND
           TITLE = 'Visitors Per Saturday' AND
           SIGNATURE = 'Copyright(C) 2002, Andy Duncan' AND
           X-AXIS = 'Month' AND
           Y-AXIS = 'Visitors' AND
           Z-AXIS = 'Monument' AND
           COLORS=(white) AND
           SHOWGRID = 1"
                    );
$sth->execute;
my $row = $sth->fetchrow_arrayref;

open(BAR, '>/tmp/spiritaxis.png');
binmode BAR;
print BAR $$row[0];
close BAR;

$dbh->do('DROP TABLE spiritaxis');
--snip--

This works like a charm, producing a neat 3D barchart.

Now, if I am replacing the string values composing X-axis with date
datatypes, as in this example:

--snip--
use DBI;
use strict;
my $dbh= DBI->connect('dbi:Chart:', undef, undef, { PrintError => 1,
RaiseError => 1 });

$dbh->do('CREATE TABLE spiritaxis (
        Dates date,
        Visitors integer,
        Monument varchar(11))');

my @dates = qw(2007-01-01 2007-02-01 2007-03-01 2007-04-01 2007-05-01
2007-06-01 2007-07-01 2007-08-01 2007-09-01 2007-10-01 2007-11-01
2007-12-01);
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my @monuments = qw(Stonehenge Avebury SilburyHill Glastonbury
WhiteHorse);

my $sth = $dbh->prepare('INSERT INTO spiritaxis VALUES(?, ?, ?)');

foreach my $date (@dates) {
        foreach my $visitors (@monuments) {
              $sth->execute($date, 1 * int(rand(2000)), $visitors);
        }
}

$sth = $dbh->prepare(
   "SELECT BARCHART, IMAGEMAP
      FROM spiritaxis
     WHERE WIDTH=1000 AND HEIGHT=600 AND
           TITLE = 'Visitors Per Saturday' AND
           SIGNATURE = 'Copyright(C) 2002, Andy Duncan' AND
           X-AXIS = 'Dates' AND
           Y-AXIS = 'Visitors' AND
           Z-AXIS = 'Monument' AND
           COLORS=(white) AND
           SHOWGRID = 1"
                    );
$sth->execute;
my $row = $sth->fetchrow_arrayref;

open(BAR, '>/tmp/spiritaxis.png');
binmode BAR;
print BAR $$row[0];
close BAR;

$dbh->do('DROP TABLE spiritaxis');

--snip--

Now the graph is produced BUT all bars are not represented correctly
(everything is collapsed on a single graphical area, with all domain
values overlapped). I have a correct behavior if I change datatypes
from date to e.g. varchar(20), but they're no more dates...

Thanks for help & congrats for this great module!
Fred.

Reply via email to