Hello Everyone,

The code I'm including makes the line graph I want, except that no points are 
plotted.  It comes out as an empty graph with only the 0 for elevation on the 
Y-axis label and the first date, 2001-01-01, on the X-axis label.  I have 
absolutely no idea why.  I've tried two methods for doing this, which I've 
marked in my code.  I am a novice at this, so I'm sure my code could be 
*much* better.  Please be merciful. :) -- Michelle

Here's my code:

#! /usr/bin/perl -wT

use DBI;
use CGI::Carp qw(fatalsToBrowser);

### variables to count results ###
$xcount = 0;
$ycount = 0;

### connect to my database ###
$dbh = DBI->connect("DBI:mysql:mydatabase", "username", "password") || 
die $DBI::errstr;

### form sql statement ###
$graphsql = "SELECT loc_id, elevation, date FROM mrddaily
             WHERE loc_id = 1 AND date <= 20010105 AND date >= 20010101";

### prepare and execute query ###
$sth = $dbh->prepare($graphsql);
$sth->execute();

### store query results ###
while (@ary = $sth->fetchrow_array()) {
   if (@ary[0] == 1) {
      push (@y, @ary[1]);
      $ycount++;
      push (@x, @ary[2]);
      $xcount++;
   }
}

### make DBD::Chart object ###
$dbh = DBI->connect('dbi:Chart:') || die "Cannot connect\n";

### create table to hold values ###
$dbh->do('CREATE TABLE line (date DATE, elevation FLOAT)');

### add data to be plotted ###
$sth = $dbh->prepare('INSERT INTO line VALUES( ?, ?)');

################## first failed method ##################
# (I know this one puts the values in the table because I checked it in 
mySQL)        
#for ($i=0, $j=0; $i<$xcount, $j<$ycount; $i++, $j++) { 
#      $sth->execute(@x[$i], @y[$j]);                   
#}                                                      
#########################################################

################# second failed method ##################
# (I don't really understand this one,                  
#  but it looked like what I needed in the example)                    
$sth->func(1, \@x, chart_bind_param_array);             
$sth->func(2, \@y, chart_bind_param_array);             
                                                        
%stsary = ();                                           
$sth->func(\%stsary, chart_bind_param_status);          
#########################################################

$sth->execute;

### render chart ###
$rsth = $dbh->prepare("SELECT LINEGRAPH FROM line
                       WHERE WIDTH=600
                       AND HEIGHT=400
                       AND X-AXIS=\'Date\'
                       AND Y-AXIS=\'Elevation\'
                       AND TITLE=\'Choke Canyon Elevation\'
                       AND COLOR=(red)
                       AND SHOWPOINTS=1
                       AND SHOWGRID=1
                       AND SHAPE=(fillcircle)
                       AND BACKGROUND=lgray
                       AND X-ORIENT=\'VERTICAL\'");
$rsth->execute;
$rsth->bind_col(1,\$buf);
$rsth->fetch;
            
### output chart to browser ###
print "Content-type: img/png\n\n";
print "$buf";


Reply via email to