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:
ie;
$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:
ie(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();
}