我设置
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;
解决方法
好的我找到了.只需使用modulo将条目数除以要跳过的标签数,并将其用作偏移量.看起来GD :: Graph总是要打印最后一个标签,所以无法控制,但你可以控制第一个标签打印.似乎向后看,但无论如何.
my $graph = GD::Graph::lines->new(400,500); my $skip = int ((@tmpDate * 8)/(400-50) + 1); # a function of # of data points,more skip. $graph->set( r_margin => 2,x_label_skip => $skip,x_tick_offset => @tmpDate % $skip,# ensure last label doesn't overwrite second-to-last label ) or die $graph->error;