travisbickle34 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I was wondering if it is possible to generate a two-line linegraph using GD::Graph. i.e. a single graph with 2 lines running alongside each other (with corresponding data points each sharing the same x-value but having different y-values...) Thanks in advance, tb34

Replies are listed 'Best First'.
Re: GD::Graph Query
by terra incognita (Pilgrim) on Jul 26, 2005 at 16:10 UTC
    You can do this by setting two_axes. I have found letting GD::Graph set the range of the Y axis works better than manually setting them. You can label the Y axis by setting the y1_label and y2_label values.
    use strict; use GD::Graph::lines; my @data = ( [1, 2, 3, 4, 5, 6, 7, 8, 9,], [ 8, 8.25, 8.5, 8.35, 8.76, 8.21, 8.6, 8.8, 8.5], [ 57.4, 57.6, 57.8, 57.9, 57.4, 58.5, 57, 57.87, 58.34] ); my $my_graph = new GD::Graph::lines (600, 400); $my_graph->set( title => "My Graph", x_label => 'X axis label', y1_label => 'Y1 axis label', y2_label => 'Y2 axis label', boxclr => '#C0C0C0', two_axes => 1, ); $my_graph->set_legend("data set 1", "data set 2"); my $gd = $my_graph->plot(\@data) or die $my_graph->error; open(IMG, '>file.gif') or die $!; binmode IMG; print IMG $gd->gif; close IMG;
Re: GD::Graph Query
by muntfish (Chaplain) on Jul 26, 2005 at 15:38 UTC

    Yes, you can have as many lines as you like, and they can all have different colours, patterns etc. I found the documentation for GD::Graph pretty useful.

    If you could let us know what you've tried so far, we can probably help further.


    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&
      Thanks, but I've just discovered how to do it. Just pass an extra array to the graph method apparently!

      Cheers anyway!