Charts/graphs in Perl - some cautionary notes

I started something that I hoped would be a very small and quick project, but it looks like it's close to impossible to draw a decent XY scatter plot in Perl. Here are two cautionary notes:

GD::Graph can't do numerical X-axes

It's right here in the documentation that data on the X-axis in any GD::Graph graph will always be evenly spaced. This is despite the facts that GD::Graph has no problem whatsoever with numerical Y-axis data, and that GD::Graph has no problem whatsoever with you submitting numerical data on the X-axis in the first place. It just casts the numerical data to a string and evenly spaces the strings.

And no, the workaround mentioned in the documentation doesn't work. That makes it impossible to do an XY scatter plot in GD::Graph. Since GD::Graph is the graphing package for Perl, this is a pretty glaring shortcoming.

Chart::Gnuplot doesn't work on Windows

Of course I downloaded gnuplot before trying this, and set up the command line so that the module would find it successfully when called at the command line. What I didn't realise until I read the documentation was that by default this module outputs a PS file, then converts that PS file to the file format you want (i.e., PNG) using a third-party image manipulation program called ImageMagick. Chart::Gnuplot doesn't go out of its way to tell you if ImageMagick isn't installed. It just blindly calls convert at the command line and assumes that this will work:

my $convert = 'convert';
my $cmd = "$convert -rotate 90 $temp $temp".".$imgfmt 2>&1";

On Linux, convert is the image conversion program which comes with ImageMagick.

On Windows, of course, convert is a command for converting FAT and FAT32 volumes to NTFS.

Now you can see where that absolutely maddening and inscrutable error, "Invalid Parameter - 90", comes from. The "-rotate 90" parameter is meaningless to Windows convert, and it is Windows convert which emits the error. You would be forgiven for not knowing that this program was ever being invoked, of course. Last time I checked, gnuplot was perfectly capable of outputting PNGs.

To fix this, you need to download and install ImageMagick (which runs to a whopping 41.9MB and there's no portable 64-bit version) and set $chart->convert("C:\...\convert.exe"); so that it knows where to find the program.

I still haven't got it to work yet:

convert.exe: Postscript delegate failed `C:...Tempp_PRwRJnYzplot.tmp': No such file or directory @ error/ps.c/ReadPSImage/806.

I may just bite the bullet and figure out how to pass commands directly to gnuplot. (gnuplot has online documentation, right? Well, there's a 2MB PDF you can download. So, no.)


Oh wait! "gswin32c.exe is installed on your computer when you install Ghostscript. Ghostscript is required by ImageMagick to interpret Postscript and PDF image files." And Ghostscript is another 14.9MB and not available in a portable form. It seems to have finally worked, though.

What is up with programs requiring other programs to work correctly but not telling you so?