GD::Graph 条形图列值
GD::Graph Bar Chart column values
我正在使用 GD::Graph
模块。我需要在图表的每一列上方写下该列对应的值。我应该怎么做?
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use GD::Graph::bars3d;
sub stringToDec {
my $ustring = '';
for my $char (split //, shift){
if(ord($char)>127){
$ustring .= "&#" . (unpack("U", $char)+848) . ";";
} else {
$ustring .= $char;
}
}
return $ustring;
}
my @time = ('00:00', '03:00', '06:00', '09:00', '12:00', '15:00');
my @site1 = ( 80 , 30 , 15 , 40 , 250 , 340 );
my @data = (\@time, \@site1);
my $graph = GD::Graph::bars3d->new(800, 300);
$graph->set_title_font('arial.ttf', 9);
$graph->set_y_label_font('arial.ttf', 9);
$graph->set_legend_font('arial.ttf', 9);
$graph->set(
y_label => 'Кол-во',
title => 'Кол-во подключенных по месяцам',
dclrs => [ ('green', 'blue') ],
bar_spacing => 15,
) or warn $graph->error;
$graph->set_legend('LAN', 'Ч.сектор');
my $image = $graph->plot(\@data) or die $graph->error;
print "Content-type: image/png\n\n";
print $image->png;
用数据点绘制数据点值
Sometimes you will want to plot the value of a data point or bar above
the data point for clarity. GD::Graph allows you to control this in a
generic manner, or even down to the single point.
show_values
Set this to 1 to display the value of each data point above the point
or bar itself. No effort is being made to ensure that there is enough
space for the text.
$graph->set(show_values => 1);
我正在使用 GD::Graph
模块。我需要在图表的每一列上方写下该列对应的值。我应该怎么做?
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use GD::Graph::bars3d;
sub stringToDec {
my $ustring = '';
for my $char (split //, shift){
if(ord($char)>127){
$ustring .= "&#" . (unpack("U", $char)+848) . ";";
} else {
$ustring .= $char;
}
}
return $ustring;
}
my @time = ('00:00', '03:00', '06:00', '09:00', '12:00', '15:00');
my @site1 = ( 80 , 30 , 15 , 40 , 250 , 340 );
my @data = (\@time, \@site1);
my $graph = GD::Graph::bars3d->new(800, 300);
$graph->set_title_font('arial.ttf', 9);
$graph->set_y_label_font('arial.ttf', 9);
$graph->set_legend_font('arial.ttf', 9);
$graph->set(
y_label => 'Кол-во',
title => 'Кол-во подключенных по месяцам',
dclrs => [ ('green', 'blue') ],
bar_spacing => 15,
) or warn $graph->error;
$graph->set_legend('LAN', 'Ч.сектор');
my $image = $graph->plot(\@data) or die $graph->error;
print "Content-type: image/png\n\n";
print $image->png;
用数据点绘制数据点值
Sometimes you will want to plot the value of a data point or bar above the data point for clarity. GD::Graph allows you to control this in a generic manner, or even down to the single point.
show_values
Set this to 1 to display the value of each data point above the point or bar itself. No effort is being made to ensure that there is enough space for the text.
$graph->set(show_values => 1);