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.
90 lines
2.6 KiB
90 lines
2.6 KiB
#!/usr/bin/perl -w
|
|
#
|
|
# $Id: linegraph.pl $
|
|
#
|
|
|
|
use strict;
|
|
use GD;
|
|
use GD::Text::Align ;
|
|
use GD::Graph::linespoints ;
|
|
# use GD::Graph::bars ;
|
|
# use GD::Graph::hbars ;
|
|
# use GD::Graph::Data ;
|
|
use GD::Graph::colour qw(:colours);
|
|
use CGI qw(:standard);
|
|
use Data::Dumper;
|
|
|
|
my $graph = new GD::Graph::linespoints () ;
|
|
my $xdim = param('xdim');
|
|
if (not $xdim) {$xdim = 500;}
|
|
my $ydim = param('ydim');
|
|
if (not $ydim) {$ydim = 200};
|
|
# my $NoLegend = param('nolegend') ;
|
|
# if (not $NoLegend) {$NoLegend = 0} ;
|
|
# my $Three_D = 1 ;
|
|
# if (param('not3d')) {$Three_D = 0;}
|
|
my @labels = split(/:/,param('labels'));
|
|
warn "LinesPoints Labels " . param('labels') ;
|
|
my @datasets = split(/::/,param('values')) ;
|
|
my @data = () ;
|
|
my @datanew = () ;
|
|
my $dataset ;
|
|
my $dataindex = 0 ;
|
|
# $data[$dataindex] = \@labels ;
|
|
# $dataindex ++ ;
|
|
$graph->set_legend(@labels) ;
|
|
foreach $dataset (@datasets) {
|
|
warn "LinesPoints Data $dataset" ;
|
|
@datanew = split(/:/,$dataset) ;
|
|
$data[$dataindex] = \@datanew ;
|
|
$dataindex ++ ;
|
|
}
|
|
|
|
my @parm_colors = split(/:/,param('colors'));
|
|
add_colour('decentblue' => [32,112,255]);
|
|
# my $colors = $graph->get('dclrs');
|
|
# $colors->[2] = 'decentblue';
|
|
my $colour ; my $index = 0 ;
|
|
# foreach $colour (@parm_colors) {
|
|
# $colors->[$index] = $colour ;
|
|
# $index ++ ;
|
|
# }
|
|
# 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' => 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("Helvetica");
|
|
# $graph->set_label_font("/var/www/x4/Fonts/VERDANAB.TTF",12);
|
|
#$graph->set_legend_font("/var/www/x4/Fonts/verdana.ttf",10);
|
|
# $graph->set_value_font("/var/www/x4/Fonts/VERDANAB.TTF",12);
|
|
|
|
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);
|
|
my @gdt = ();
|
|
binmode STDOUT;
|
|
print header("image/png");
|
|
print $gd->png;
|
|
|