GertMT has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
While using GD::Graph::bars I'm trying to create a chart showing values per a certain calendardate. My current solution gives a result. However I would like to show zero values for calendardates that are not in my data. Is there a certain option for this?
Thanks for any reply.
Gert
#!/usr/bin/perl -w use strict; use diagnostics; use Data::Table; use GD::Graph::bars; my $table = new Data::Table( [ [ 20070410, 20070415, 20070417 ], [ 10, 20, 15 ] +], [ 'A', '+B' ], 1 ); print $table->html; for my $graph ( GD::Graph::bars->new( 700, 150 ) ) { $graph->set( 'y_number_format' => '%d', transparent => 0, values_vertical => 1, show_values => 1, ); $graph->set( 'x_labels_vertical' => 1 ); my $gd = $graph->plot( $table->colRefs( [ 0, 1 ] ) ); open( IMG, ">voorraad.png" ) or die $!; binmode IMG; print IMG $gd->png; close IMG; }

Replies are listed 'Best First'.
Re: GD::graph time-scale option?
by jettero (Monsignor) on May 09, 2007 at 11:16 UTC

    There's definitely no automatic way to do it. But it seems simple enough to write a little gap filler.

    -Paul

      Thanks, for pointing me in a direction I understand. It'll take me some time to work it out. Good challenge though.
      hi,
      guess I'd like to make a _new_ list of all dates occuring between start_date and end_date. Subsequently mix the two lists (one with the initial data and the new one) and do some filtering to get rid of the double occurences and put 'undef' where there is no data/value.
      I'll be posting the final script if I've done what I describe above but in the meantime I'm trying to find out the following:

      What is the best way to get an array with dates between start_date and end_date while using date::manip?

      thanks,
      Gert
        What is the best way to get an array with dates between start_date and end_date while using date::manip?

        Something like the following might be what you want:
        #!/usr/bin/perl use strict; use warnings; use Date::Manip; my @dates = ParseRecur( '0:0:0:1:0:0:0', # every day '100 days ago', # base before start_date 'last Monday', # start_date 'next Friday' ); # end_date foreach my $date ( @dates ) { print "$date\n"; }
        Hth