You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
4 months ago
|
#!/usr/bin/perl -w
|
||
|
#
|
||
|
# $Id: piechart.pl,v 1.4 2004/02/10 17:08:43 jeffo Exp $
|
||
|
#
|
||
|
|
||
|
use strict;
|
||
|
use GD;
|
||
|
use GD::Graph::pie;
|
||
|
use GD::Graph::colour qw(:colours);
|
||
|
use CGI qw(:standard);
|
||
|
#use Data::Dumper;
|
||
|
|
||
|
my $xdim = param('xdim');
|
||
|
if (not $xdim) {$xdim = 500;}
|
||
|
my $ydim = param('ydim');
|
||
|
if (not $ydim) {$ydim = 200};
|
||
|
my $graph = GD::Graph::pie->new($xdim,$ydim);
|
||
|
my @data = ([map("$_ %",split(/:/,param('values')))],
|
||
|
[split(/:/,param('values'))],
|
||
|
);
|
||
|
my @labels = split(/:/,param('labels'));
|
||
|
add_colour('decentblue' => [32,112,255]);
|
||
|
my $colors = $graph->get('dclrs');
|
||
|
$colors->[2] = 'decentblue';
|
||
|
#print STDERR Dumper($colors);
|
||
|
my $maxlen = 0;
|
||
|
foreach (@labels) {if ($maxlen < length($_)) {$maxlen = length($_);}}
|
||
|
my $legendwidth = 9*($maxlen+2) + 16 + 32;
|
||
|
my %opt = ('transparent' => 0,
|
||
|
'dclrs' => $colors,
|
||
|
'bgclr' => 'white',
|
||
|
'fgclr' => 'black',
|
||
|
'accentclr' => 'black',
|
||
|
'labelclr' => 'black',
|
||
|
'textclr' => 'black',
|
||
|
'l_margin' => 1,
|
||
|
'b_margin' => 1,
|
||
|
't_margin' => 1,
|
||
|
'r_margin' => $legendwidth,
|
||
|
'3d' => 1,
|
||
|
'pie_height' => 40,
|
||
|
'start_angle' => 180);
|
||
|
if (param('title')) {$opt{'title'} = param('title');}
|
||
|
if (param('xlabel')) {$opt{'x_label'} = param('xlabel');}
|
||
|
if (param('ylabel')) {$opt{'y_label'} = param('ylabel');}
|
||
|
if (param('ymax')) {$opt{'y_max_value'} = param('ymax');}
|
||
|
if (param('ymin')) {$opt{'y_min_value'} = param('ymin');}
|
||
|
if (param('yticknum')) {$opt{'y_tick_number'} = param('yticknum');}
|
||
|
|
||
|
$graph->set(%opt) or die $graph->error;
|
||
|
$graph->set_title_font(gdGiantFont);
|
||
|
$graph->set_label_font(gdGiantFont);
|
||
|
$graph->set_value_font(gdGiantFont);
|
||
|
|
||
|
my $gd = $graph->plot(\@data) or die $graph->error;
|
||
|
my $xoff = $xdim - $legendwidth + 8;
|
||
|
my $yoff = ($ydim - 16*(2*@labels+1))/2;
|
||
|
#my $deltay = ($ydim - 2*$yoff - 32)/@labels;
|
||
|
#open(IMG, '>file.png') or die $!;
|
||
|
my $black = $gd->colorClosest(0,0,0);
|
||
|
$gd->rectangle($xoff,$yoff,$xdim-8,$ydim-$yoff,$black);
|
||
|
for (my $i=0; $i < @labels; $i++) {
|
||
|
$gd->rectangle($xoff+16,$yoff+16+$i*32,$xoff+32,$yoff+32+$i*32,$black);
|
||
|
my $color = $gd->colorAllocate(_rgb($colors->[$i]));
|
||
|
$gd->fill($xoff+24,$yoff+24+$i*32,$color);
|
||
|
$gd->string(gdGiantFont,$xoff+40,$yoff+18+$i*32,$labels[$i],$black);
|
||
|
}
|
||
|
binmode STDOUT;
|
||
|
print header("image/png");
|
||
|
print $gd->png;
|