badpearl has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple data sets on one gd::graph
by GrandFather (Saint) on Aug 09, 2007 at 02:10 UTC | |
by badpearl (Initiate) on Aug 09, 2007 at 12:42 UTC | |
by GrandFather (Saint) on Aug 09, 2007 at 21:11 UTC | |
|
Re: Multiple data sets on one gd::graph
by CountZero (Bishop) on Aug 09, 2007 at 06:14 UTC |