gpt4 book ai didi

perl - 如何防止 GD::Graph 写入最后一个 X 标签并覆盖我的其他标签?

转载 作者:行者123 更新时间:2023-12-04 15:14:25 25 4
gpt4 key购买 nike

我设置了 x_label_skip 跳过标签,但它仍然尝试显示最后一个标签,并且它正在覆盖另一个标签,看起来很乱。不应该写最后一个标签。它应该跳过最后一个标签。我将要跳过的标签数量设置为有多少数据点的函数。

这是它的样子:



代码:

my $graph = GD::Graph::lines->new(400, 500);
$graph->set(
r_margin => 2,
x_label => 'Date',
y_label => 'Price',
title => "$symbol1, $symbol2",
dclrs => [ qw(lred lblue lgreen lyellow lpurple cyan lorange) ],
transparent => 0,
x_labels_vertical => 1,
x_label_skip => int ((@tmpDate * 8)/(400-50) + 1), # a function of # of data points, each label 8px. More labels, more skip.
) or die $graph->error;

最佳答案

好的,我找到了。只需使用模数将条目数除以要跳过的标签数,并将其用作偏移量。似乎 GD::Graph 总是想打印最后一个标签,所以无法控制,但您可以控制要打印的第一个标签。对我来说似乎是倒退,但无论如何。

my $graph = GD::Graph::lines->new(400, 500);
my $skip = int ((@tmpDate * 8)/(400-50) + 1); # a function of # of data points, each label 8px. More labels, more skip.
$graph->set(
r_margin => 2,
x_label => 'Date',
y_label => 'Price',
title => "$symbol1, $symbol2",
dclrs => [ qw(lred lblue lgreen lyellow lpurple cyan lorange) ],
transparent => 0,
x_labels_vertical => 1,
x_label_skip => $skip,
x_tick_offset => @tmpDate % $skip, # ensure last label doesn't overwrite second-to-last label
) or die $graph->error;

关于perl - 如何防止 GD::Graph 写入最后一个 X 标签并覆盖我的其他标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9961530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com