C
Chad Thomson
Hi All.
I'm relatively new to Perl, and have been somewhat successful using
the GD::Graph and Graph3d modules.
I'm using this procedure as a CGI app to generate graphs.
I've got an issue where, I'm setting up the @data array and when my
image renders in the browser, it has a width, and height, but still
appears as a broken link.
I've tried CARP and multiple other techniques to figure out what's
happening. Obviously unsuccessful.
I believe the issue is directly related to the @data array, and/or
it's reference.
I've attached a "scaled-down" snipped of what I'm working with, any
advice is appreciated.
Chad.
<snip>
use CGI ':standard';
use GD::Graph::bars3d;
# Create CGI Object
my $q = new CGI;
my $alpha = "abcdefghijklmnopqrstuvwxyz";
my $ii = 0;
my $paramname;
# a sample url would be:
# ?xlabels=this,that,theother&groups=joe,ed,frank&a=1,2,3&b=4,5,6&c=7,8,9
# get X labels
my @labels = [ split (/\,/, $q->param ("xlabels")) ];
# get data groups
my @datagroups = split (/\,/, $q->param("groups"));
# @data is supplied to the generator @plot-time
my @data = ( @labels );
# get data sets
# data is on query string as: a=1,2,3&b=4,5,6
my @datasets;
foreach (@datagroups) {
$paramname = substr $alpha, $ii, 1;
push @datasets, [ split ( /\,/ , $q->param($paramname) ) ];
$ii++;
}
# @datasets should have a structure like this now.
# @datasets = ( [ 12,15,20 ]
# ,[ 30,10,25 ]
# ,[ 15,25,55 ]
# );
=DEBUGcomments
need to transpose datasets into @data:
@data = ( [ labels ]
,[ 12,30,15 ]
,[ 15,10,25 ]
,[ 15,25,55 ]
);
=cut
foreach (@datasets) {
# will have an array here
# get each entry in the array
# add/push it to an array on @data
for ($i=0;$i<= $#{$_}; $i++) {
push @{$data[$i+1]}, $_->[$i];
carp @{$data[$i+1]};
}
}
my $my_image = $my_graph->plot(\@data) or die $my_graph->error;
print "Content-type: image/png\n\n";
binmode ( STDOUT );
print $my_image->png;
</snip>
I'm relatively new to Perl, and have been somewhat successful using
the GD::Graph and Graph3d modules.
I'm using this procedure as a CGI app to generate graphs.
I've got an issue where, I'm setting up the @data array and when my
image renders in the browser, it has a width, and height, but still
appears as a broken link.
I've tried CARP and multiple other techniques to figure out what's
happening. Obviously unsuccessful.
I believe the issue is directly related to the @data array, and/or
it's reference.
I've attached a "scaled-down" snipped of what I'm working with, any
advice is appreciated.
Chad.
<snip>
use CGI ':standard';
use GD::Graph::bars3d;
# Create CGI Object
my $q = new CGI;
my $alpha = "abcdefghijklmnopqrstuvwxyz";
my $ii = 0;
my $paramname;
# a sample url would be:
# ?xlabels=this,that,theother&groups=joe,ed,frank&a=1,2,3&b=4,5,6&c=7,8,9
# get X labels
my @labels = [ split (/\,/, $q->param ("xlabels")) ];
# get data groups
my @datagroups = split (/\,/, $q->param("groups"));
# @data is supplied to the generator @plot-time
my @data = ( @labels );
# get data sets
# data is on query string as: a=1,2,3&b=4,5,6
my @datasets;
foreach (@datagroups) {
$paramname = substr $alpha, $ii, 1;
push @datasets, [ split ( /\,/ , $q->param($paramname) ) ];
$ii++;
}
# @datasets should have a structure like this now.
# @datasets = ( [ 12,15,20 ]
# ,[ 30,10,25 ]
# ,[ 15,25,55 ]
# );
=DEBUGcomments
need to transpose datasets into @data:
@data = ( [ labels ]
,[ 12,30,15 ]
,[ 15,10,25 ]
,[ 15,25,55 ]
);
=cut
foreach (@datasets) {
# will have an array here
# get each entry in the array
# add/push it to an array on @data
for ($i=0;$i<= $#{$_}; $i++) {
push @{$data[$i+1]}, $_->[$i];
carp @{$data[$i+1]};
}
}
my $my_image = $my_graph->plot(\@data) or die $my_graph->error;
print "Content-type: image/png\n\n";
binmode ( STDOUT );
print $my_image->png;
</snip>