I'm new to this so please excuse ignorance. Thanks in advance for your help.

Output looks like this

I've searched the docs but can't see an example to do what I want. I'm wanting to put two separate lines on a gd::graph which I can achieve. The problem is aligning them AND retaining the second set of x-axis labels distinguished (and preferably below) below the first (ie. I want the green x-axis labels below the red, otherwise they don't all fit and it gets very confusing). I guess the question is really how do you offset the x-axis labels without off-setting the graphs and sort out the mess I've ended up with...

Code looks like this:

$sth->bind_columns(\($year,$pop,$notes,$name)); my (@pop_loop); while ($sth->fetch) { my (%row); $row{YEAR} = $year; $row{POP} = $pop; $row{SEQNO} = $seqno; $row{NOTES} = $notes; push (@pop_loop,\%row); if ($pop > $maxy) { $maxy=$pop } # print "$year - $pop\n"; if ($year > 1900) { push(@{$graph_data1[0]},$year); push(@{$graph_data1[1]},$pop); $data1_exists = 1; } else { push(@{$graph_data2[0]},$year); push(@{$graph_data2[1]},$pop); $data2_exists = 1; } } if ($maxy == 0) { # This is not ideal as it needs to be updated with every census! $row{YEAR} = "2001"; $row{POP} = "N/A"; push (@pop_loop,\%row); return(\@pop_loop,$sth->rows) } if (length($name) < 20) { $name = "POPULATION TREND: ".uc($name); } else { $name = "POP TREND: ".uc($name); } ##The maximum value for printed on the new line.If the max value on th +e y axis is less than 1000, to round it up to the next full value, ##that max value should be multiply by 1.2/100 and again multiply by 1 +00 if ($maxy < 1000) { $maxy=ceil(($maxy*1.2)/100)*100; } elsif ($maxy < 10000) { $maxy=ceil(($maxy*1.2)/1000)*1000; } elsif ($maxy < 100000) { $maxy=ceil(($maxy*1.2)/10000)*10000; } elsif ($maxy > 100001) { $maxy=ceil(($maxy*1.2)/100000)*100000; } my $mygraph = GD::Graph::linespoints->new(320, 160); $mygraph->set( x_label => 'YEAR', y_label=> 'POPULATION', title => $name, fgclr => '#804000', labelclr => '#2B60DE', textclr => '#000000', line_types=> [1], line_width=> 2, long_ticks=> 1, dclrs => ['red'], markers => [5], y_max_value =>$maxy, y_min_value => 0, y_label_skip => 0, y_label_position => 1/2, x_label_position => 1/2, #bgclr => 'blue', labelclr => 'dblue', axislabelclr => 'red', textclr => 'red', text_space=> 4, tick_length => 4, y_tick_number=> 4, show_values => 1, x_labels_vertical => 0, ) or warn $mygraph->error; $mygraph->set_legend_font(GD::gdMediumBoldFont); $mygraph->set_title_font(GD::gdMediumBoldFont); $mygraph->set_x_axis_font( "Giant" ); $mygraph->set_x_label_font(GD::gdMediumBoldFont); $mygraph->set_y_axis_font( "luximr", 9 ); $mygraph->set_y_label_font(GD::gdMediumBoldFont); if ($data1_exists) { $myimage = $mygraph->plot(\@graph_data1) or die +$mygraph->error } $mygraph->set( textclr => '#000000', line_width=> 2, dclrs => ['green'], y_label_position => 1/2, x_label_position => 1/2, #bgclr => 'blue', labelclr => 'dblue', axislabelclr => 'green', textclr => 'red', text_space=> 4, long_ticks=>0, tick_length => 0, y_tick_number=> 4, show_values => 1, x_labels_vertical => 0, x_label => '', y_label => '' ) or warn $mygraph->error; if ($data2_exists) { $myimage = $mygraph->plot(\@graph_data2) or die $ +mygraph->error } open (OUTPUT, ">$hostpath/graphs/pop$seqno.png"); print OUTPUT $myimage->png; close OUTPUT;


In reply to Multiple data sets on one gd::graph by badpearl

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.