Greetings,
I encountered an issue while using the line chart with two axes. The
problem is when the data set across a great range, especially when one
set contains negative numbers, the chart cannot be drawn very nicely.
One set will look okay, but most likely the other set will look like a
straight line.
The problem is it seems there is no way set a minimum value above 0 when
one data set contains a negative number. The 0 will always be there and
aligned between two axes. (see test_chart_1.png) Even manually setting
the minimum value to above 0 does not work. Although this will result
the chart looks a bit better, but the two data sets will be too apart.
(see test_chart_2.png)
#!/usr/bin/perl -w
# Change above line to point to your perl binary
use CGI ':standard';
use GD::Graph::lines;
use strict;
# Both the arrays should same number of entries.
my @data = (['01', '02', '03', '04' ],
[80, 90, 85, 75],
[-6, -15, -25, 5]);
my $mygraph = GD::Graph::lines->new(600, 300);
$mygraph->set(
#x_label => '',
#y_label => '',
title => 'Test Chart',
# Draw datasets in 'solid', 'dashed' and 'dotted-dashed' lines
line_types => [1, 2],
# Set the thickness of line
line_width => 2,
# Set colors for datasets
dclrs => ['blue', 'green'],
two_axes => 1,
#y1_min_value => 60,
#y1_max_value => 100,
#y2_min_value => -30,
#y2_max_value => 10,
) or warn $mygraph->error;
$mygraph->set_legend_font(GD::gdMediumBoldFont);
$mygraph->set_legend('Data Set 1', 'Data Set 2');
my $myimage = $mygraph->plot(\@data) or die $mygraph->error;
print "Content-type: image/png\n\n";
print $myimage->png;
Thanks in advance for any help you can provide on the problem.