2

我正在使用该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;

在此处输入图像描述

4

1 回答 1

1

GD::图

用数据点绘制数据点值

有时,为了清楚起见,您可能希望在数据点上方绘制数据点或条形的值。GD::Graph 允许您以通用方式控制它,甚至可以控制到单点。

显示值

将此设置为 1 以显示点或条本身上方的每个数据点的值。没有努力确保文本有足够的空间。

$graph->set(show_values => 1);

条形图

于 2020-05-20T14:13:14.423 回答