homepage Welcome to WebmasterWorld Guest from 54.211.80.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
need help with GD::Graph
longcan




msg:3822966
 6:47 pm on Jan 9, 2009 (gmt 0)

Hi,

I am trying to use perl's GD::graph to draw pie and bar in CGI program for wed browser. I have 2 example pl files which i could not get GD:graph to draw the pie and bar correctly. I have 6 values but i can only see 1 pie or 1 bar.

here is the code for pie:

use GD::Graph::pie;
use CGI;

my $q = new CGI;

my @col= {"1st","2nd","3rd","4th","5th","6th"};
my @val= {100,250,390,50,25,10};

my $graph = new GD::Graph::pie(500,500);
my @data = ([@col], [@val]);
$graph->set_label_font('ARIAL.TTF', 12);
$graph->set_value_font('ARIAL.TTF', 12);
$graph->set(
title => 'Performance Result',
label => 'Performance Result Pie',
axislabelclr => 'black',
pie_height => 36,
l_margin => 15,
r_margin => 15,
start_angle => 235,
transparent => 0,
dclrs => [qw(green pink cyan red yellow blue)],
show_values => 1,
);
print $q->header("image/gif");
binmode STDOUT;
print $graph->plot(\@data)->gif;

Here is the code for bar:

use GD::Graph::bars;
use CGI;

my $q = new CGI;

my @col= {"1st","2nd","3rd","4th","5th","6th"};
my @val= {150,250,390,50,25,10};

my $graph = new GD::Graph::bars(500,500);
my @data = ([@col],[@val]);

$graph->set(
title => 'Performance Result',
x_label => 'CPU #',
y_label => 'CPU %',
shadow_depth => 4,
shadowclr => 'dred',
transparent => 0,
dclrs => [qw (green pink cyan red yellow blue)],
show_values => 1,
);

print $q->header("image/gif");
binmode STDOUT;
print $graph->plot(\@data)->gif;

What have i missed in the script ?

I have tried both IE7 and Morzilla but got the same problem.

any help is appreciated.

 

longcan




msg:3823004
 7:41 pm on Jan 9, 2009 (gmt 0)

Ok,

I found the bug:

I have to define my @data as :

@col= ["1st","2nd","3rd","4th","5th","6th"];
@val= [150,250,390,50,25,10];
my @data = (@col,@val);

phranque




msg:3823149
 11:01 pm on Jan 9, 2009 (gmt 0)

welcome to WebmasterWorld [webmasterworld.com], longcan!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved