Subject: | show_values problem in stacked bars |
I want to create a chart with horizontal stacked bars, where the value
for each bar is printed inside of the bar itself. I'm not sure this
can even be done.
Working with the samples provided with GDGraph (1.35), I can create
the horizontal stacked bar graph just fine, but the values end up
getting printed in an odd manner. For the code below, the values that
are printed for each bar don't end up 4 pixels outside of the bar
(which I expect since I haven't gotten to trying to move them inside
of the bar yet), and the values seem to be randomly chosen from either
of the series.
Any suggestions for:
1) getting the values to appear correctly for stacked horizontal bar
graphs
2) getting the values to appear inside of the bar itself, rather than
to the right (if I use the option values_space set to a negative
number, the values seem to appear to the left of the bar).
Thanks!
Derek
# This code demonstrates the problem I am having with labels inside
the bars
# of a stacked bar chart
use strict;
use GD::Graph::hbars;
my @data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
[ 1, 1.5, 3, 2, 3, 1.5, 3, 4, 4 ]
);
my $graph = GD::Graph::hbars->new(400, 300);
$graph->set_legend('Pass', 'Fail');
$graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'Some simple graph',
y_max_value => 10,
y_tick_number => 10,
y_label_skip => 2,
bar_spacing => 8,
cumulate => 'true',
dclrs => [ qw( green lred ) ],
show_values => 1,
values_space => 4,
)
or warn $graph->error;
my $format = $graph->export_format;
$graph->plot(\@data)->$format();
save_chart($graph,'bugs_graph');
sub save_chart
{
my $chart = shift or die "Need a chart!";
my $name = shift or die "Need a name!";
local(*OUT);
my $ext = $chart->export_format;
open(OUT, ">$name.$ext") or
die "Cannot open $name.$ext for write: $!";
binmode OUT;
print OUT $chart->gd->$ext();
close OUT;
}