Ask a Question related to PERL Miscellaneous, Design and Development.
-
Chad Thomson #1
GD: Graph Data Array Issue
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>
Chad Thomson Guest
-
What is the easiest way to graph MySQL data?
I'm guessing I'm not the only person in the world who wants to graph some data collected in a MySQL database. I have not found any great tutorials... -
Issue with a mailer and a data array
Hi there, I hope someone can help me with this, I am fairly new to PHP and am struggling to get a simple order form to send a mail message form... -
SVG::Graph::Data::Datum and labels
Hi I want to create a simple svg bar chart with labels for each bar, I can see that I can add a label via SVG::Graph::Data::Datum but i dont see... -
components for dynamically displaying data chart or graph in ASP
Hello, I tried to find some components I can use to dynamically generate chart or graph from database in ASP. It seems to me that only some... -
Graph Data Sheet Won't Sort Properly
The problems is that I am trying to create a graph on a Form with MMM YY as the X Axis. The data is based on a query of two queries with the final... -
Martien Verbruggen #2
Re: GD: Graph Data Array Issue
On 4 Sep 2003 08:45:39 -0700,
Chad Thomson <chad_thomson18@hotmail.com> wrote:Renders in the browser? How do you mean, and what is the URL to the> 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.
script below you use?
Have you also checked the web server logs for error messages?> I've tried CARP and multiple other techniques to figure out what's
> happening. Obviously unsuccessful.
It looks here like you're use $ii and $alpha to get an alphabetically> 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++;
> }
incrementing letter, right? Perl's automagical increment can do this
for you:
my $paramname = "a";
foreach my $dg (@datagroups)
{
push @datasets, [split /,/ , $q->param($paramname)];
$paramname++;
}
And the number of labels should be the same as the number of array> # @datasets should have a structure like this now.
> # @datasets = ( [ 12,15,20 ]
> # ,[ 30,10,25 ]
> # ,[ 15,25,55 ]
> # );
references in @datasets here, right?
So, each column here represents a set of data that will become a line
or bar group in the chart?
^^>=DEBUGcomments
> need to transpose datasets into @data:
> @data = ( [ labels ]
> ,[ 12,30,15 ]
> ,[ 15,10,25 ]
> ,[ 15,25,55 ]
20?
[ I wish you hadn't chosen a three-by-three data set. It's easier to> );
>=cut
visualise this sort of stuff with non-square sets ]
But, given this, it looks like for each @datagroup, you're reading in
the values for the three data sets that at that point need to be
appended to the sets. The GD::Graph::Data module that prepares data
sets for GD::Graph has an "add_point" method for this.
I'd probably do something like:
use GD::Graph::Data;
my $dataset = GD::Graph::Data->new();
my $paramname = "a";
foreach my $dg (@datagroups)
{
$dataset->add_point("dummy", split /,/ , $q->param($paramname));
$paramname++;
}
for my $i (0 .. $#labels)
{
$dataset->set_x($i, $labels[$i]);
}
And then use $dataset instead of \@data. It's quite easy to lose track
of how to work with those data structures.
This probably generates an error. Check your web server log.> my $my_image = $my_graph->plot(\@data) or die $my_graph->error;
Alternatively, if you use the fatalsToBrowser argument with CGI, you
should see the error messages in your browser.
Use the CGI methods for this, since you've loaded the module anyway.> print "Content-type: image/png\n\n";
print $q->header(-type => "image/png");
You should use the binmode as the first thing you do on STDOUT, before> binmode ( STDOUT );
the above print even.
Without really deconstructing what you did with that data set, I can't
tell whether that is what is wrong. I'd advise you to get check the
GD::Graph::Data module, which can help with this particular structure,
and maybe use Data::Dumper to dump out the structure to your browser,
so you can see what it looks like.
Also, for testing, don't use square data sets. It's much easier to
debug a non-square one.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | Can't say that it is, 'cause it ain't.
|
Martien Verbruggen Guest
-
Gregory Toomey #3
Re: Graph Data Array Issue
"Chad Thomson" <chad_thomson18@hotmail.com> wrote in message
news:ebe52c7.0309040745.9e49377@posting.google.com ...I do the same sort of thing & a superficial look at your code shows no> 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.
obvious errors. CARP will not work as you are not generating HTML.
I suggest opening a file (in / tmp if necessary) and writing debugging
messages there. As you have a broken link you may not even be calling the
program.
You can try writing your png file to disk (as 'test.png') instead of stdout
and try to load test.png in the browser.
You might want to look at the HTML I have at [url]www.ipo-australia.com[/url] to
generate graphs.
gtoomey
Gregory Toomey Guest



Reply With Quote

