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

Modern Monks,

I'll be writing a script to generate some graphs as images from scratch. Basic stuff like bar charts of data from an SQL query. Item a = 5, Item b = 13, Item c = 7.5, for example. I'll need to include in the image some textual labelling and titling.

I have never done this before and my nkowledg eof the common modules is what I've read in preparing for this.

Looking at technical options right now.

  1. GD::Graph - as I understand it, generates .png files. Has lots of facilities purpose-designed for creating charts, so will be "relatively" (heavily quialified) easy to get up and running. BUT, just how well do .png files scale when a user copies them off the web page that's returned and trie to paste it into Word, or PowerPoint, or something else to include in their report?
  2. XML::Writer & SVG - I read an interesting article, here:
    http://www.xml.com/pub/a/2001/07/11/creatingsvg.html
    about writing XML-based SVG image files using Perl. It looks slick, AND the images are scalable vector graphics. BUT, as I understand it, SVG is an Adobe format that requires a plug-in in many browsers - although MSIE 6 appears to display it just fine.

Anyone else had to decide between the two, or have an opinion?

Thanks.




Forget that fear of gravity,
Get a little savagery in your life.
  • Comment on Graphics Creation: GD &.png, or XML::Writer & SVG?

Replies are listed 'Best First'.
Re: Graphics Creation: GD &.png, or XML::Writer & SVG?
by Joost (Canon) on Dec 17, 2007 at 02:21 UTC
Re: Graphics Creation: GD &.png, or XML::Writer & SVG?
by aquarium (Curate) on Dec 17, 2007 at 01:51 UTC
    SVG is not Adobe format. They did used to make a IE plugin for SVG. Firefox has SVG support built-in. If you just want to get the job done, and quickly, SVG is not your horse.
    generate your graph with GD or other into suitably well supported format at a high enough resolution so that reasonable scaling doesn't produce jaggies
    if you graphs are going to be very simple bar charts only, you can even get away with using javascript and CSS to generate them.
    the hardest line to type correctly is: stty erase ^H
Re: Graphics Creation: GD &.png, or XML::Writer & SVG?
by aufflick (Deacon) on Dec 17, 2007 at 01:45 UTC
      I appreciate the lateral thinking and the time to post a reply, so this isn't intended personally, but I can't resist commenting on Google: I wouldn't trust Google with my corporate data as far as I could throw them after they compiled search histories on users for two years before telling them.
Re: Graphics Creation: GD &.png, or XML::Writer & SVG?
by andreas1234567 (Vicar) on Dec 17, 2007 at 06:41 UTC
    Depending on the nature of the data you would like to plot, I would also have considered:
    --
    Andreas
Re: Graphics Creation: GD &.png, or XML::Writer & SVG?
by scorpio17 (Canon) on Dec 17, 2007 at 15:22 UTC

    I have used the GD library for simple things like bar charts, pie charts, etc. It works great when you want to read data (from say, a database) and generate a simple plot or chart on-the-fly for a web page. It can create images in .gif, .png, or .jpg formats. I usually prefer .gif. There was a period of time when support for .gif was dropped due to copyright issues, but that is no longer the case. Just make sure you have the latest version installed.

Re: Graphics Creation: GD &.png, or XML::Writer & SVG?
by renodino (Curate) on Dec 17, 2007 at 16:47 UTC
    Basic stuff like bar charts of data from an SQL query

    Precisely what DBIx::Chart was developed to do ;^)

    That said, what medium are you intending to display this in ? If I assume web based, you might consider a <canvas> based solution, like Plotr, Plotkit, or dojo.gfx.chart


    Perl Contrarian & SQL fanboy
Re: Graphics Creation: GD &.png, or XML::Writer & SVG?
by Anonymous Monk on Dec 17, 2007 at 17:11 UTC
    GD::Graph is great, in my opinion, for simple graphing. A function for error-bars would've been nice, but I wrote one into the bars.pm myself without too much trouble. I actually find the best combo to be GD + ImageMagick which lets you do a lot of post-processing like re-sizing, labeling, rotating etc that is much harder in GD.