I have been trying to make some graphs using GD::Graph::lines. I have run into a snag when trying to use multiple Y axes. I can configure the 1st axis with no problem at all. My problem is configuring the ticks for the second axis.

I have tried using attributes like y1_tick_number, y2_tick_number, etc. but get the error No attribute 'y2_tick_number'

I have tried specifying an array such as y_tick_number  => [3,30] but the second element seems to get ignored.

I have searched the documentation and the web but can't seem to find an answer. The idea is to provide a different set of ticks for the second data set. I would like to have 15 ticks numbered 10, 20, 30, etc. on the right side of the graph. Any help will be greatly appreciated.

Here is a short example of my test code:
#!/usr/bin/perl use strict; use GD::Graph::lines; my @data = ( ["Mar","Apr","May","Jun","Jul"], [5,2,10,6,4], [100,80,50,60,20] ); my $graph = GD::Graph::lines->new(800, 600); $graph->set( title => 'Test Graph', two_axes => 'true', use_axis => [1,2], x_label => 'Month', y1_label => 'Units', y1_max_value => 15, y1_min_value => 0, y_tick_number => [15,15], #second element get ignored y_label_skip => 0, y2_label => 'Profit', y2_max_value => 150, y2_min_value => 0, #y2_tick_number => 15, #throws error #y2_label_skip => 0 #throws error ) or die $graph->error; my $gd = $graph->plot(\@data) or die $graph->error; open(IMG, '>/var/www/html/file.gif') or die $!; binmode IMG; print IMG $gd->gif; close IMG; exit;
Chris Rogers

In reply to GD::Graph and Multiple Y Axes by ChrisR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.