2017-10-08 75 views
-1

我使用Perl的GD::Graph 模块来绘制信号轮廓。我设法让几乎所有东西看起来都是正确的,只是由于某种原因,在y轴和第一个绘制点之间存在一个恼人的和不需要的间隙。我怎样才能消除这一点?Perl-GD ::图 - 图和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

一旦加载完成,并启用相关的按钮,有三个可用的可视化组件,以帮助使天线和预测信号的可能有用:

  • 一个谷歌地图查找地标指向天线朝向
  • 甲UK军械测量地图表示信号路径
  • 垂直信号轮廓示出潜在障碍物

这是最后一个,它是通过按下表格底部的信号配置文件按钮获得的,并显示在两张地图下面的页面底部,这是此处所关注的。我期待取代它,因为它目前使用谷歌图表工具 API,不幸的是它已被谷歌弃用,并且应该在2015年结束,但幸运的是迄今为止它们一直在运行。

我一直在寻找一个替代来到谷歌投掷开关的那一天,但是已经取得了非常有限的成功。如果有人知道我可以在我自己的服务器上安装一个包来取代Google的图表绘图功能,那么我会非常感激的了解它。

+0

请一次只问一个问题。 – Borodin

+3

请使用'strict strict启动您的所有Perl文件;使用警告;'。 – melpomene

回答

1

这感觉就像代码中的一个错误的错误,但我现在没有时间进一步调查。我就注意到一个变通似乎是更换:

x_min_value  => 0, 

x_min_value  => 1, 
+0

谢谢,但我现在意识到数据的末尾和绘图区域的边缘之间的右端还有间隙。这个建议确实将情节向左移动,但是因此相应地增加了右侧的差距。 – CharlesMacfarlane