Welcome to WebmasterWorld Guest from 54.234.63.187

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

need help with GD::Graph

     

longcan

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

5+ Year Member



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

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

5+ Year Member



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

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], longcan!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month