6

I set x_label_skip to skip labels, but it still tries to display the very last label and it is overwriting the other label, and looks messy. It shouldn't be writing the last label. It should be skipping the last label. I set the number of labels to skip as a function of how many data points there are.

This is what it looks like:

Code:

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;
4

2 回答 2

5

好的,我找到了。只需使用模将条目数除以要跳过的标签数,并将其用作偏移量。似乎 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;
于 2012-04-01T03:32:54.620 回答
0

x_last_label_skip => 1完全按照您的需要工作,只需跳过最后一个标签。可能它在 2012 年没有实施,但现在已经实施了。

于 2015-04-14T05:19:49.690 回答