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

Dear Monks, I want to plot a simple graph and have decided to use DBD::Chart::Graph mainly because of the number of colours available and because you can plot scatter graphs.

I have basically copied code from the cpan web-site for this module but I can't get it to work but I don't get errors either. Can anyone spot the problem? Thanks!

#!/biol/programs/perl580/bin/perl use DBD::Chart::Plot; my $img = DBD::Chart::Plot->new(); my @k = ('1','1','3','5'); my @h = ('0.1','0.5','0.4','0.9'); $img->setPoints(\@k, \@h, 'blue line nopoints'); $img->setOptions ( title => 'My Graph Title', xAxisLabel => 'my X label', yAxisLabel => 'my Y label' ); print $img->plot; open (WR,'>plot3.png') or die ("Failed to write file: $!"); binmode WR; # for DOSish platforms print WR $img->plot(); close WR;

Formatting repaired by davido

Replies are listed 'Best First'.
Re: DBD::Chart::Plot ??
by itub (Priest) on Jan 24, 2005 at 16:52 UTC
    The problem is that you have to specify the file format when you call the plot method. That is, replace
    print $img->plot;

    with

    print $img->plot('png');

    Yes, the documentation is wrong, and the module should complain or have a default if no format is provided.

    Added: The format you provide has to be the name of one of the "Image Data Output Methods", as listed in the GD documentation.

      Thanks a million itub ! - now it works
Re: DBD::Chart::Plot ??
by CountZero (Bishop) on Jan 24, 2005 at 15:27 UTC
    Did you check the return value of the setpoints function? As per the docs it returns a positive integer upon success and an undef on failure.

    Update I tried your code and it doesn't work for me either. The problem is with the plot function which doesn't return anything.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: DBD::Chart::Plot ??
by holli (Abbot) on Jan 24, 2005 at 15:21 UTC
    Are you sure you have all rerequisites installed? These are, according to the docs of DBD::Chart:
  • Perl 5.6.0 minimum
  • DBI 1.14 minimum
  • DBD::Chart::Plot 0.80 (included with this package)
  • GD X.XX minimum
  • GD::Text X.XX minimum
  • Time::HiRes
  • libpng
  • zlib
  • libgd
  • jpeg-6b

  • holli, regexed monk