Perl - GD :: Graph - 绘图和y轴之间的间隙

时间:2017-10-08 13:55:08

标签: perl

我正在使用Perl的GD::Graph 用于绘制信号轮廓的模块。我已经设法让几乎所有东西都看起来正确,除了由于某种原因在y轴和第一个绘制点之间存在刺激性和不需要的间隙。我该怎样消除这个?

以下是我编写的测试页面的代码(它显示在我的localhost服务器上,但我尝试在我的实时服务器上安装它,以便其他人可以看到结果,它出错 - 我认为我的实时网站必须缺少一些Perl模块):

#!perl

use POSIX;
use CGI ':standard';
use GD::Graph::area;
use GD::Graph::colour qw(:colours);

use strict;

# Graph constants
GD::Graph::colour::add_colour( axes    => [ 0x00, 0x00, 0x00 ] );
GD::Graph::colour::add_colour( earth   => [ 0x00, 0x00, 0x00 ] );
GD::Graph::colour::add_colour( beam    => [ 0x00, 0x00, 0x00 ] );
GD::Graph::colour::add_colour( clutter => [ 0x66, 0x33, 0x00 ] );
GD::Graph::colour::add_colour( terrain => [ 0x00, 0x99, 0x00 ] );
GD::Graph::colour::add_colour( earth   => [ 0x00, 0x00, 0x00 ] );
GD::Graph::colour::add_colour( fre1    => [ 0xFF, 0x33, 0x00 ] );
GD::Graph::colour::add_colour( fre2    => [ 0xFF, 0x66, 0x00 ] );
GD::Graph::colour::add_colour( sky1    => [ 0x33, 0x66, 0x99 ] );
GD::Graph::colour::add_colour( sky2    => [ 0x66, 0x99, 0xCC ] );

# All arrays should same number of entries.
my @data = (
    [ 0,   undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 5,   undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 10,  undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 15,  undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 20,  undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 25,  undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 30, undef, undef, undef, undef, undef, undef, undef, undef, undef ],
    [ 450, 458,   459,   458,   457,   455,   453,   451,   449,   447,   444,   441,   438,   435,   432,   429, 426,   422,   420,   416,   413,   409,   406,   402,   399,   395,   391,   388,   384,   381,   376, 373,   369,   365,   361,   358,   353,   350,   345,   341,   337,   333,   329,   325,   321,   316, 313,   308,   304,   299,   296,   291,   286,   282,   277,   273,   268,   265,   259,   256,   250, 247,   241,   236,   232,   227,   223,   217,   213,   208,   204,   198,   194,   188,   184,   178, 173,   168,   163,   158,   152,   148,   142,   137,   131,   126,   120,   115,   109,   102,   97, 90,    85,    78,    72,    64,    58,    50,    43,    32 ],
    [ 450, 453,   451,   449,   447,   444,   441,   438,   435,   432,   428,   426,   422,   418,   415,   411, 408,   404,   400,   396,   393,   389,   386,   381,   378,   374,   369,   366,   361,   358,   353, 350,   345,   342,   337,   334,   329,   326,   321,   316,   313,   308,   305,   300,   296,   291, 288,   283,   279,   274,   271,   266,   261,   257,   252,   249,   244,   240,   235,   231,   226, 222,   217,   212,   208,   203,   199,   194,   190,   185,   181,   176,   172,   166,   162,   157, 151,   147,   142,   138,   132,   128,   123,   118,   113,   108,   103,   98,    92,    87,    82, 76,    71,    65,    60,    54,    49,    42,    36,    27 ],
    [ 450, 445,   440,   436,   432,   428,   423,   419,   414,   411,   406,   402,   397,   392,   389,   384, 380,   375,   372,   367,   363,   358,   354,   350,   346,   341,   336,   332,   328,   324,   319, 315,   310,   307,   302,   298,   293,   290,   285,   280,   276,   271,   268,   263,   259,   254, 250,   246,   242,   237,   233,   228,   224,   220,   215,   211,   206,   203,   198,   194,   189, 186,   181,   176,   172,   167,   164,   159,   155,   150,   147,   142,   138,   133,   129,   125, 120,   116,   111,   107,   102,   99,    94,    90,    85,    82,    77,    73,    68,    63,    60, 55,    51,    46,    43,    38,    34,    29,    25,    21 ],
    [ 450, 437,   429,   423,   416,   411,   405,   400,   394,   389,   383,   379,   373,   367,   363,   357, 353,   347,   343,   337,   333,   328,   323,   318,   314,   309,   303,   299,   294,   290,   285, 281,   275,   272,   266,   262,   257,   253,   248,   243,   239,   234,   231,   226,   222,   217, 213,   208,   205,   200,   196,   191,   186,   183,   178,   174,   169,   166,   161,   157,   153, 149,   144,   140,   136,   132,   128,   124,   120,   116,   112,   108,   104,   100,   97,    92,  88,    84,    80,    77,    73,    69,    65,    62,    58,    55,    51,    48,    44,    40,    37, 34,    31,    27,    25,    22,    19,    17,    15,    14 ],
    [ 450, 432,   422,   415,   406,   400,   393,   387,   380,   375,   368,   363,   357,   350,   345,   339, 334,   328,   324,   318,   313,   307,   303,   297,   293,   287,   281,   277,   271,   267,   262, 258,   252,   248,   243,   239,   233,   229,   224,   219,   215,   210,   206,   201,   197,   192, 188,   183,   180,   175,   171,   166,   161,   158,   153,   149,   145,   141,   136,   133,   128, 125,   120,   116,   112,   108,   105,   100,   97,    93,    89,    85,    82,    78,    75,    71,  67,    64,    60,    57,    53,    50,    46,    43,    40,    37,    34,    31,    28,    25,    22, 19,    17,    15,    13,    11,    10,    8,     8,     9 ],
    [ 387, 344,   266,   240,   222,   215,   190,   156,   120,   76,    99,    151,   167,   158,   167,   158, 157,   148,   114,   89,    87,    28,    11,    11,    12,    12,    12,    13,    13,    13,    13,  23,    15,    34,    39,    38,    72,    107,   122,   134,   128,   128,   121,   100,   82,    16,  16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    15,    15,    20,    20,  15,    15,    15,    15,    14,    14,    14,    14,    60,    53,    13,    13,    12,    12,    12,  12,    11,    11,    11,    10,    10,    9,     9,     9,     8,     8,     7,     7,     6,     6,  5,     5,     4,     4,     3,     2,     2,     1,     26 ],
    [ 386, 343,   261,   235,   217,   210,   185,   151,   105,   61,    84,    136,   152,   143,   152,   153, 152,   143,   109,   84,    82,    23,    11,    11,    12,    12,    12,    13,    13,    13,    13,  23,    15,    34,    34,    33,    67,    102,   117,   129,   123,   128,   121,   100,   82,    16,  16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    15,    15,    15,    15,  15,    15,    15,    15,    14,    14,    14,    14,    60,    53,    13,    13,    12,    12,    12,  12,    11,    11,    11,    10,    10,    9,     9,     9,     8,     8,     7,     7,     6,     6,  5,     5,     4,     4,     3,     2,     2,     1,     26 ],
    [ 0,   1,     1,     2,     3,     3,     4,     4,     5,     5,     6,     6,     7,     7,     8,     8,   9,     9,     9,     10,    10,    11,    11,    11,    12,    12,    12,    12,    13,    13,    13,  14,    14,    14,    14,    14,    15,    15,    15,    15,    15,    15,    15,    15,    16,    16,  16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    16,    15,    15,    15,    15,  15,    15,    15,    15,    14,    14,    14,    14,    13,    13,    13,    13,    12,    12,    12,  11,    11,    11,    10,    10,    10,    9,     9,     8,     8,     8,     7,     7,     6,     6,  5,     5,     4,     4,     3,     2,     2,     1,     1 ]
);

my $dist = 32.745;

my $mygraph = GD::Graph::area->new( 800, 300 );

$mygraph->set(
    transparent       => 0,
    l_margin          => 3,
    b_margin          => 3,
    t_margin          => 5,
    r_margin          => 5,
    text_space        => 3,
    axis_space        => 7,
    tick_length       => -5,
    accent_treshold   => 100,
    x_label_position  => 0.5,
    bgclr             => 'white',
    fgclr             => 'black',
    boxclr            => 'sky1',
    labelclr          => 'black',
    axislabelclr      => 'black',
    textclr           => 'black',
    x_label           => 'Kilometres',
    y_label           => 'Metres',
    x_label_skip      => 15.27,
    x_last_label_skip => 1,
    x_min_value       => 0,
    x_max_value       => $dist,
    borderclrs        => [qw(fre2 fre1 black fre2 sky1 clutter terrain axes)],
    dclrs             => [qw(fre2 fre1 fre1 fre2 sky1 clutter terrain axes)]
) or warn $mygraph->error;

my $myimage = $mygraph->plot( \@data ) or die $mygraph->error;

print "Content-type: image/png\n\n";

print $myimage->png;

背景资料

我目前有一个非常成功的网页,使英国公民能够将地面电视天线对准给定的发射机。 Here's an example of it in action

加载完成后,相关按钮启用后,有三个可用的可视组件可帮助对齐天线并预测信号的可能用途:

  • 用于查找地标以指示天线朝向
  • 的Google地图
  • 显示信号路径的英国军械测量地图
  • 显示潜在障碍物的垂直信号配置文件

这是最后一个,通过按下表格底部的信号配置文件按钮获得,并显示在两张地图下方的页面底部,这是值得关注的这里。我正在寻找替换它,因为它目前使用的是谷歌图表工具 API,不幸的是谷歌已经弃用它,并且应该在2015年结束,但幸运的是到目前为止他们一直在运行。< / p>

我一直在寻找,因为在Google推出交换机的那一天取而代之,但取得了非常有限的成功。如果有人知道我可以在我自己的服务器上安装一个软件包来取代谷歌的图表绘图功能,我将非常感谢你知道它。

1 个答案:

答案 0 :(得分:1)

这感觉就像代码中的一个错误,但我现在没有时间进一步调查。我只是要注意,解决方法似乎是要替换:

x_min_value       => 0,

x_min_value       => 1,