CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Can't locate object method "png" via package "GD::Graph::bars" ...

 



rocheteau
New User

Jul 16, 2010, 12:54 PM

Post #1 of 3 (1083 views)
Can't locate object method "png" via package "GD::Graph::bars" ... Can't Post

Hi,
I'm working through a book on Perl graphics but when I execute the following code I get the error message:
Can't locate object method "png" via package "GD::Graph::bars".
find `perl -e 'print "@INC"'` -name '*.pm' -print | grep bars --> indicated the module was present.
Any help would be appreciated. Thanks


Code
#!/usr/bin/perl -w 
use strict;
use GD;

use GD::Graph::bars;
my @data = (
['frogs','fish','toads','rodents'],
[ 8, 3, 1, 2],
);
my $chart = GD::Graph::bars->new(700,500);
$chart->set(title => 'Ostrich diet');
$chart->set_title_font('arialbd', 24);
$chart->set_x_axis_font('arial', 16);
$chart->set_y_axis_font('arial', 16);
my $gd_object = $chart->plot(\@data);

open(PIC, '>picfile.png') or die "Could not open the picture file.\n";

# make sure we are writing to a binary stream
binmode PIC;

# Convert the image to PNG and print it on standard output
print PIC $chart->png;



winfinit
User

Jul 17, 2010, 9:21 PM

Post #2 of 3 (1061 views)
Re: [rocheteau] Can't locate object method "png" via package "GD::Graph::bars" ... [In reply to] Can't Post

i never used that module, but i peaked at cpan just now, and it looks like you are executing png method on a wrong object, in your case, you have to run png method on $gd_object, that is returned after ->plot is being executed, so $gd_object->png or you can chain your actions:

$chart->plot(\@data)->png

hope that helps.


rocheteau
New User

Jul 19, 2010, 1:53 PM

Post #3 of 3 (1048 views)
Re: [winfinit] Can't locate object method "png" via package "GD::Graph::bars" ... [In reply to] Can't Post

Thanks for the reply. You're correct. Total bungle by me. Appreciate the help nonetheless.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives