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.
 
 
 
 
 
 

64 lines
1.8 KiB

#!/usr/bin/perl -w
#
# $Id: bargraph.pl,v 1.9 2004/05/11 21:00:18 jeffo Exp $
#
use strict;
use GD;
use GD::Graph::bars;
use GD::Graph::hbars;
use GD::Graph::bars3d;
use CGI qw(:standard);
#use Data::Dumper;
my @data = ([split(/:/,param('labels'))],
[map(($_ eq ''? undef : $_),split(/:/,param('values')))]);
if (param('values2')) {push @data,[map(($_ eq ''? undef : $_),split(/:/,param('values2')))];}
#print STDERR Dumper(\@data);
my $max = 0;
foreach (@{$data[1]}) {defined $_ and $max = ($max > $_? $max : $_);}
if ($data[2]) {foreach (@{$data[2]}) {defined $_ and $max = ($max > $_? $max : $_);}}
$max *= 1.2;
$max=5*(int($max/5)+1);
my $xdim = param('xdim');
if (not $xdim) {$xdim = 500;}
my $ydim = param('ydim');
if (not $ydim) {$ydim = 150};
my $graph;
if (param('hbar')) {
#print STDERR "hbar set\n";
$graph = GD::Graph::hbars->new($xdim,$ydim);
} else {
$graph = GD::Graph::bars->new($xdim,$ydim);
#print STDERR "hbar not set\n";
}
my %opt = ('transparent' => 0,
'x_label_position' => 0.5,
'show_values' => 1,
'y_max_value' => $max,
'overwrite' => 1);
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_x_label_font(gdGiantFont);
$graph->set_y_label_font(gdGiantFont);
$graph->set_x_axis_font(gdGiantFont);
$graph->set_y_axis_font(gdGiantFont);
$graph->set_values_font(gdGiantFont);
my $gd = $graph->plot(\@data) or die $graph->error;
#open(IMG, '>file.png') or die $!;
binmode STDOUT;
print header("image/png");
print $gd->png;