Slashdot Mirror


Custom Charts w/ Perl and GD

An anonymous reader writes "This article describes techniques you can use to create new levels of usefulness in your dynamically generated charts with Perl and GD. Cook up some automatically generated graphs for your organizational meetings or live enterprise directory data. Annotate the charts with readable text that delivers more information than the standard pie chart. Using the power of GD and Perl, you can link various data and images together to create sophisticated charts that will help bring visual interest to your applications."

9 of 112 comments (clear)

  1. For the Pythonista wanting charts and graphs... by MarkEst1973 · · Score: 2, Informative

    ... there's matplotlib and there's reportlab for PDFs. Both are excellent open source packages, and I can tell you from experience that reportlab has outstanding support. I recently posted a question to their mailing list and received three intelligent replies within an hour.

  2. Re:These charts look like shit by dbcad7 · · Score: 3, Informative
    I think the examples are meant to show how it works, not to wow you with art.

    The code looks easy enough to experiment with your own artwork, so I look forward to seeing how much better you can do.

    --
    waiting for ad.doubleclick.net
  3. Re:wow! by Coryoth · · Score: 5, Informative

    For those of us who just want to generate some simple graphs for papers and such, what do people use? I've messed with Excel, gnuplot, R, and now I'm using ploticus. Anyone have better solutions? To be honest I would suggest you try messing with Gnuplot some more -- it is actually a lot better, and produces much nicer plots, than it seems at first. The trick is to use a different terminal type than "x11", which is pretty crappy; the output looks remarkably different if you use "png", "svg" or "postscript". Here are some examples of plots I've done with Gnuplot: [1], [2], [3] [4] (for the last link, note that vertical text alignment renders fine in inkscape, just not on Wikipedia -- download the svg file to see).

    If that's still not tickling your fancy then I would suggest matplotlib which is actually pretty versatile, and produces good looking plots. There's also PyX if you're looking for slightly more raw graphical interaction with nice output. Truth be told, however, after messing around with many of the same options you have, I've found that Gnuplot, once you get over the initial learning hurdle and figure out how to turn out nice looking plots, is the fastest and easiest way to turn out plots and charts.
  4. Ruby / Gruff by carlivar · · Score: 2, Informative

    Or use Ruby with Gruff.

    --
    Vote Libertarian
  5. Use JPGraph instead by yahyamf · · Score: 2, Informative
    JPGraph uses PHP and GD, and they have dozens of very fancy graphs along with excellent documentation and code examples. You can have beautiful looking graphs in a few minutes with less than a screen full of php code.

    I think it's dual licensed, with a very modest fee for commercial use.

  6. Re:How does one do this in HTML? by LordLucless · · Score: 2, Informative

    You don't. You use a library like GD and a scripting language to generate the charts as images(alternatively, if your chart is representing static data, you can just whip up a static image in excel/gnuplot/whatever). There are also libraries built on top of GD (I use jpGraph with PHP) which simplify the process.

    You can probably emulate a bar graph using tables, if you're particularly anal about doing it in HTML. Hell, you could probably do a line graph with a whole tonne of 1-pixel cells in a table, but I wouldn't recommend it.

    --
    Just because you're paranoid doesn't mean there isn't an invisible demon about to eat your face
  7. Re:Ah, charts in Perl... by Noksagt · · Score: 2, Informative

    Grace can produce some nice results, but the Perl interface to it is just a wrapper around their terrible command line interface (maybe it's improved in the last few years, but when I tried it it was almost entirely undocumented and nigh-unusable).
    I like grace a lot. I use it through the GUI & occasionally through python, so can't comment extensively on the perl interfaces. Neither Chart::GRACE nor Chart::Graph::Xmgrace seem TOO obscure.

    The command line interface of grace isn't terrible--it is MUCH more powerful than most plotting software which has a GUI. I do agree it is under-documented, though. Fortunately, the developers are very responsive in the forums.
  8. Re:wow! by T-Ranger · · Score: 2, Informative

    Its not GNUPlot. Gnuplot, or gnuplot, sure. But it has exactly nothing to do with GNU.

  9. You can draw charts on the client side instead by Anonymous Coward · · Score: 1, Informative

    Some of the open source JavaScript toolkits can be used to draw charts on a browser window with inline SVG and VML. This makes it possible to draw charts on the web browser instead of having the web server draw them.

    Some examples:
    Dojo Toolkit
    I think I've seen a live charting demo on Dojo's official website, but it seems to be no longer there.

    WT Toolkit
    This one seems to be a new project, judging from the activity charts on their SourceForge page. The way they can draw 3D charts (like, pie charts, 3D bar charts) with inline SVG and VML is quite amazing though.