Subject: | Multiple bar graphs in a mixed graph will not render side by side |
Using GDGraph-1.35 (perl v5.6.1) on Windows 2000 Professional.
When drawing mixed charts with multiple bar charts and a line chart, the bar charts do not render side by side.
The following script is a combination of the provided sample scripts (sample14.pl and sample 61.pl). The resulting .png renders as expected, with the two bars on each date rendered in the same space, and the line over the entire graph. (I say as expected because you elude to this issue in the documentation.)
The intent of the script is to render two bars side by side for each date, and a line over the entire graph. Based on your documentation, it appears that you are already aware of this issue.
I just wanted to get this one on the wish list, as the fix would make my life much easier. GD::Graph is a great tool, thanks for putting it out there!
Paul Russell <parussel@yahoo.com>
use strict;
use GD::Graph::mixed;
my @data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 7, 8, 9, 10, 11],
[ 2, 2, 1, 1, 3, 2, 2, 4, 0],
[ 9, 8, 9, 5, 7, 7, 8, 3, 3] );
my $my_graph = new GD::Graph::mixed();
$my_graph->set(
types => [ qw( lines) ],
default_type => 'bars',
);
$my_graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Mixed Type Graph',
y1_max_value => 40,
y2_max_value => 8,
y_min_value => 0,
y_tick_number => 8,
y_label_skip => 1,
x_plot_values => 0,
y_plot_values => 0,
long_ticks => 1,
x_ticks => 0,
legend_marker_width => 24,
line_width => 3,
marker_size => 5,
bar_width => 4,
#bar_spacing => 1,
transparent => 0,
values_vertical => 1,
values_format => "%4.1f",
x_label_position => 1/2,
cumulate => 0,
overwrite => 1 );
$my_graph->set_legend( qw( incomming outgoing total ) );
$my_graph->plot(\@data) or die $my_graph->error;
save_chart($my_graph, 'bars_all_over_each_other');
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;
}
use strict;
use GD::Graph::mixed;
## define your data set
my @data = (
["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
[ 1, 2, 5, 6, 7, 8, 9, 10, 11],
[ 2, 2, 1, 1, 3, 2, 2, 4, 0],
[ 9, 8, 9, 5, 7, 7, 8, 3, 3] );
my $my_graph = new GD::Graph::mixed();
$my_graph->set(
types => [ qw( lines) ],
default_type => 'bars',
);
$my_graph->set(
x_label => 'X Label',
y_label => 'Y label',
title => 'A Mixed Type Graph',
y1_max_value => 40,
y2_max_value => 8,
y_min_value => 0,
y_tick_number => 8,
y_label_skip => 1,
x_plot_values => 0,
y_plot_values => 0,
long_ticks => 1,
x_ticks => 0,
legend_marker_width => 24,
line_width => 3,
marker_size => 5,
bar_width => 4,
#bar_spacing => 1,
transparent => 0,
values_vertical => 1,
values_format => "%4.1f",
x_label_position => 1/2,
cumulate => 0,
overwrite => 1 );
$my_graph->set_legend( qw( incomming outgoing total ) );
$my_graph->plot(\@data) or die $my_graph->error;
save_chart($my_graph, 'bars_all_over_each_other');
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;
}