Drawing bar and pie charts in webspeed.

progdev1

Member
Hi all,
Does anyone know how to output pie charts to screen in webspeed. Do I need a tool to do this, could anyone recommend one.
Thanks
 

progdev1

Member
It looks a good tools, unfortunately I wouldn't be able to use it due to privacy concerns. But thanks for your reply anyhow. I did hear of fly but that seems to be no longer used/available.
 

lee.bourne

Member
The perl script below can be hosted on your own server. It generates pie charts as .gifs based on parameters you pass in on the url. You'll need to make sure your installation of perl has GD::Graph installed.

#!/usr/bin/perl
#
#PIE CHART EXAMPLE
#

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use GD::Graph::pie;

$query = new CGI;
if ($query->param('values') gt '') {
$bTest = 0;
$sTitle = $query->param('title');

#array of pie chart segements
@segments = split(',', $query->param('labels'));

#arbitrary categories of values
@values = split(',', $query->param('values'));
} else {
$bTest = 1;
$sTitle = 'Weekdays';

#array of pie chart segements
@segments = qw(a b c d e f g h i j);

#arbitrary categories of values
@values = qw(6 6 6 6 7 8 9 2 3 4);
}

#3D pie chart?
$b3D = $query->param('3D');
$b3D = 0 if ($b3D eq '');

#create array of arrays for graph api
#first array is assumed to be the x-axis labels
my @table_data;
push(@table_data, \@segments);
push(@table_data, \@values);

#create graph object for canvas 400 by 400 pixels
my $my_graph = new GD::Graph::pie(400, 400);

$my_graph->set(
title => $sTitle, #chart title
axislabelclr => 'black', #colour of label segements
accentclr => 'black', #colour dividing segements
'3d' => $b3D, #3D piechart?
suppress_angle => 5, #do not label segements with values smaller than this
) || die("\nFailed to create pie chart: $my_graph->error()");

if ($query->param('colours') gt '') {
@colours = split(',', $query->param('colours'));
$my_graph->set(dclrs => \@colours);
}
#plot graph with table data
my $plot = $my_graph->plot(\@table_data);
if ($my_graph->error() gt "") {
print $my_graph->error() . "\n\n";
}

if ($bTest) {
#write graph to a file
my $pie_file = "pie_sample.gif";
open(IMG, ">$pie_file")
|| die ("\nFailed to save graph to file: $pie_file. $!");

binmode(IMG);
print IMG $plot->gif();
close(IMG);

print "\nCreated pie chart in $pie_file.";
}
else {
print "Content-type: image/gif\n\n";
binmode(STDOUT);
print $plot->gif();
}
 

atopher

New Member
I've used fusion charts (there's a no frills free version) and extJS to produce charts on web. Fusion charts has loads of examples included, ext is fairly straight forward though not so well documented.
 

progdev1

Member
I've come across fusion on my investigations; fusion looks good but, unfortunately fusion is too expensive and the no frill is non commercial only. I haven't come across extJS I will investigate. Thanks for that. Thanks for your Perl script Lee.
 
Top