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

Hi All, I am stuck up here. I need to create histogram to interpret a large data. I have installed the Histogram.pl in the 'GD::Graph::histogram '. It does not seem to work !! Has anyone used this before or is there anything that could be used to create histogram Thank you for any help that you may provide Jaya

Replies are listed 'Best First'.
Re: Histogram in Perl
by atcroft (Abbot) on Feb 17, 2005 at 22:04 UTC

    I installed the module, and tried it using the bits and snippets from the module's POD, with no luck. In digging through the package's contents, though, I found 'scripts/histogram.pl', which did work. In comparing the code there with the snippets from the POD, the issue appears to be with the data. The example in the POD for the 1.0 version shows:

    $data = [1,5,7,8,9,10,11,3,3,5,5,5,7,2,2];
    When I replaced this with:
    @data = (1,5,7,8,9,10,11,3,3,5,5,5,7,2,2);
    I had no problem with it working.

    Hope that helps.

      Thank You very much. The example is working. since i need 3 histograms, I tried using subroutine call to draw the h +istogram chart & i am not getting the results. the code in main is as follows: my $image2 = Covarion_Modules::draw_hist(\@hist); open(IMG, '>hist.png') or die $!; binmode IMG; print IMG $image2->png; and the subroutine is : sub draw_hist{ my ($h) = @_; use CGI ':standard'; use GD::Graph::histogram; @data = @$h; my $graph = new GD::Graph::histogram(400,600); $graph->set( y_label => 'Count', x_label => 'Data', title => 'A Histogram Chart', x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph->error; my $image = $graph->plot(\@data) or die $graph->error; return($image); } I am getting the error: Useless use of a constant in void context at /usr/lib/perl5/site_perl/ +5.8.0/GD/Graph/histogram.pm line 203. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.0/GD/Graph/histogram.pm line 42. Argument "" isn't numeric in numeric eq (==) at /usr/lib/perl5/site_pe +rl/5.8.0/GD/Graph/histogram.pm line 181. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.0/GD/Graph/histogram.pm line 42. Use of uninitialized value in string eq at /usr/lib/perl5/site_perl/5. +8.0/GD/Graph/histogram.pm line 42. any suggestions please

        I'm not sure what is causing the error you are seeing, but I can suggest the following variation that might work for you:

        sub draw_graph { my ( $filename, @data ) = @_; my $graph = new GD::Graph::histogram( 400, 600 ); $graph->set( x_label => 'Data', y_label => 'Count', title => 'A Histogram Chart', x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph->error; my $gd = $graph->plot( \@data ) or die $graph->error; open( IMG, '>' . $filename ) or die $!; binmode IMG; print IMG $gd->png; }

        The difference being that the graph object does not have to be passed around, since it would appear that it is only being generated and written out. To call this, you might do something like the following examples:

        foreach ( 1, 5, 7, 8, 9, 10, 11, 3, 3, 5, 5, 5, 7, 2, 2 ) { push( @data, $_ * ( $_ + 1 ) ); } draw_graph( 'test1.png', @data ); @data = ( 1, 5, 7, 8, 9, 10, 11, 3, 3, 5, 5, 5, 7, 2, 2 ); draw_graph( 'test2.png', @data );

        HTH.

Re: Histogram in Perl
by m-rau (Scribe) on Feb 17, 2005 at 23:43 UTC
Re: Histogram in Perl
by TedYoung (Deacon) on Feb 17, 2005 at 21:15 UTC

    What have you tried (code wise)? How does it not work? Error messages?

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
      I have a large 1D array of data. I need to plot the frequency of that data in the histogram format. I did plot it using 'histogram.pl' but it is not correct.(I am getting a large rectangular box) So i tried the example given in the 'histogram.pl' , to check if the module works and it also gave the same kind of result:(:( Any suggestions