#!/usr/pkg/bin/perl -w use strict; use Cwd; use GD::Graph::lines; my @foo_y1a; my @foo_y1b; my @foo_y2a; my @foo_y2b; my @foo_x; for (0 .. 99) { push @foo_x, $_; push @foo_y1a, $_ * 1.0 + 10; push @foo_y1b, $_ * 1.1 - 10; push @foo_y2a, $_ * -1.2 + 10; push @foo_y2b, $_ * -1.3 - 10; } my $graph = GD::Graph::lines->new(1024,512); $graph->set_legend('Y1A', 'Y1B', 'Y2A', 'Y2B'); $graph->set_legend_font("GD::gdFontTiny"); # Basic stuff done for all graphs. $graph->set( title => 'TWO AXES PROBLEM', transparent => 0, x_label => 'X DATA', y1_label => 'Y1 DATA', y2_label => 'Y2 DATA', two_axes => 1, use_axis => [1,1,2,2], long_ticks => 1, bgclr => '#c0c0c0', x_labels_vertical => 1, ); my $gd = $graph->plot([\@foo_x, \@foo_y1a, \@foo_y1b, \@foo_y2a, \@foo_y2b]) or print "Oops! Problem: " . $graph->error . " \n"; my $path = cwd() . '/two_axis_problem.png'; open GRAPH, ">$path"; binmode(GRAPH); print GRAPH $gd->png or print "Oops! Problem: $! \n"; ; close GRAPH; # Cause written graph to pop up in viewer. sub graph_display { my $cmd = 'display'; # UNIX default. $cmd = 'imdisplay.exe' if $Config::Config{'osname'} =~ /Win/i; system( qq|start "$cmd" "$cmd"|, qq|"$_[0]"| ) } graph_display($path);