#!/usr/bin/perl use warnings; use strict; use GD::Graph::mixed; my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 4, 9, 16, 25, 36, 49, 64, 81], # wants left: 0 .. 100 'x**2', [ 1, 1.4, 1.7, 2, 2.2, 2.4, 2.6, 2.8, 3], # wants right: 0 .. 5 '~sqrt(x)' [ 99, 88, 77, 66, 55, 44, 33, 22, 11], # wants left: 0 .. 100 '11*(10-x)', [ 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5], # wants right: 0 .. 5 '0.5x', [ 1, 2, 3, 4, 5, 4, 3, 2, 1], # wants right: 0 .. 5 '123454321' [ 98, 76, 54, 32, 10, '', '', '', ''], # wants left: 0 .. 100 'descend', ); my $my_graph = new GD::Graph::mixed( ); my %opts = ( transparent => '0', x_label => 'nth', y1_label => 'big', y2_label => 'small', title => 'Using two axes', y1_max_value => 100, y2_max_value => 5, y_tick_number => 8, y_label_skip => 2, long_ticks => 1, use_axis => [1,2,1,2,2,1], # big, small, big, small, small, big legend_placement => 'BR', x_labels_vertical => 1, x_label_position => 1/2, two_axes => 1, legend_marker_width => 100, l_margin => 10, b_margin => 10, r_margin => 20, t_margin => 10, show_values => 1, ); $my_graph->set(%opts); $my_graph->set_legend( 'x**2', '~sqrt(x)', '11*(10-x)', '0.5x', '123454321', 'descend'); save_it($my_graph, \@data, 'out1.png'); # second graph, same as the first (except for use_axis) $opts{use_axis} = [1,2,1,1,1,1]; # big, small, big, big, big my $second_graph = new GD::Graph::mixed( ); $second_graph->set(%opts); $second_graph->set_legend( 'x**2', '~sqrt(x)', '11*(10-x)', '0.5x', '123454321', 'descend'); save_it($second_graph, \@data, 'out2.png'); sub save_it { my ($graph, $data_ref, $fname) = @_; my $gd = $graph->plot($data_ref) or die $graph->error; open(my $img, '>', $fname) or die "$fname: $!\n"; binmode $img; print {$img} $gd->png; close $img; }