The legend only displays as many colors as the number of datasets, even
when you supply more arguments to set_legend(). When you set cycle_clrs
to on, the number of colors used has nothing to do with the number of
datasets -- rather, it is the number of colors in dclrs. But the legend
still only displays as many colors as the number of datasets.
In the example code below, we have 1 dataset with 6 data points, with
cycle_clrs to on, with 3 colors in dclrs. You can see three colors in
the graph. However, the legend only shows 1 color, even though we gave
three arguments to set_legend(). I should be able to show a legend entry
for each color shown.
#!/usr/bin/perl
use strict;
use warnings;
use GD::Graph::bars;
my $my_graph = GD::Graph::bars->new;
$my_graph->set(
dclrs => [ qw(lred lgreen lblue) ],
cycle_clrs => 1, # causes colors to change horizontally
) or warn $my_graph->error;
$my_graph->set_legend( qw(A B C) );
$my_graph->plot( [[1, 2, 3, 4, 5, 6],
[1, 2, 3, 4, 5, 6]] ) or die $my_graph->error;
my $ext = $my_graph->export_format;
my $graph_filename = "test.$ext";
open OUT, ">$graph_filename" or die "Cannot open for write: $!";
binmode OUT;
print OUT $my_graph->gd->$ext;
close OUT;