2012-04-01 44 views
6

我設置x_label_skip跳過標籤,但它仍然試圖顯示最後一個標籤,它覆蓋另一個標籤,看起來很混亂。它不應該寫最後的標籤。它應該跳過最後一個標籤。我設置標籤的數量作爲有多少數據點的函數跳過。如何讓GD :: Graph不寫下最後的X標籤並覆蓋其他標籤?

這是什麼樣子:

代碼:

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; 

回答

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;