How to save GD :: Graph from writing the last X shortcut and overwrite my other shortcuts?

I set x_label_skip to skip tags, but it still tries to display the most recent tag and overwrite another tag, and looks messy. He should not write the last mark. He should skip the last mark. I set the number of labels to skip based on the number of data points.

It looks like this:

the 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; 
+6
source share
2 answers

Ok, I found it. Just use modulo to split # entries by the number of labels to skip, and use this as an offset. It seems that GD :: Graph always wants to print the last label, so it cannot control it, but you can control the 1st label for printing. It seems the opposite of me, but anything.

 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; 
+5
source

x_last_label_skip => 1 works exactly as you need, just by skipping the last label. This was probably not implemented in 2012, but now it is.

0
source

Source: https://habr.com/ru/post/912158/


All Articles