Click to See Complete Forum and Search --> : creating chart on perl?


benq
05-02-2006, 10:42 AM
hello all

i,m trying to make this chart via cgi, i keep getting an error anyone can you see if there are some mistakes or anything like that.

error : internal server error 401

i have set it to be executable chmod 755.

code:

#!/usr/bin/perl

#load modules
use CGI ':standard';
use GD::Graph::bars;
use strict;
use CGI::Carp 'fatalsToBrowser';

#access database
use DBI;

$db=DBI->connect("DBI:mysql:1231233:www.mysql.co.uk","2332313","233231") || die;


$query=$db->select name, sum(takings) from wes_sales join branches where id=branch_id and year=2005 group by branch_id order by branch_id;

$query->execute();

#array
$count=0;
while (@newrow=$q->fetchrow_array) {
$branches[$count]=$newrow[0];
$takings[$count]=$newrow[1];
$count++;
}

#array of arrays
@chartdata=(\@branches, \@takings);

#set graph and res
$graph=GD::Graph::bars->new(1000,500);

#plot graph
$graph->set(x_label => 'Branch', y_label => 'Sales', title => 'Annual Sales by Branch for 2005', y_max_value => 800000000);

#mage is neither text nor html but a binary file
binmode STDOUT;

#display graph as png
print "Content-type: image/png\n\n";
print $graph->plot(\@chartdata)->png();

any ideas would be great?

thanks

CyCo
05-02-2006, 04:11 PM
The obvious reason for the error would be your attempt to use the strict pragma, yet not declare your variables with my. Any other errors would only be a guess, since we don't know what the error log may contain.