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."

34 of 112 comments (clear)

  1. These charts look like shit by Anonymous Coward · · Score: 2, Interesting

    When will open source advocates learn to delegate the graphic design aspect of their work to professionals? Plenty of designers would be more than happy to contribute, if only the programming types in charge of these projects would admit they're better at making code than graphics.

    1. Re:These charts look like shit by Solra+Bizna · · Score: 2, Funny

      I'm better at making code than graphics.

      Now, if only other people were better at waiting on my every graphical need, free of charge...

      -:sigma.SB

      --
      WARN
      THERE IS ANOTHER SYSTEM
    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:These charts look like shit by dodobh · · Score: 4, Insightful

      The code is out there. Whenever the graphics folks want to start contributing, they can.

      --
      I can throw myself at the ground, and miss.
    4. Re:These charts look like shit by EsbenMoseHansen · · Score: 2

      KDE have a quite a few very good contributors who are of the more graphical persuation. I believe firefox have a few as well. But they are always in short supply even compared to coders, so if you know any, please direct them to the appropriate sites. (I'm sure it is the same with Gnome, but I agree with Linus on that one).

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    5. Re:These charts look like shit by grcumb · · Score: 3, Insightful

      There is an underlying assumption that even though the coders apparently can't do graphic design worth jack, that graphic designers can somehow code worth jack. Most graphic designers aren't coders, and most coders aren't graphic designers. The disciplines aren't mutually exclusive, but most in one field can't do much of value in the arts of the other field. Usually, it's better to have mutual cooperation than expect graphic designers to come in on their own.

      I agree with what you're saying, but I think you've got the onus wrong. As someone with design and coding experience, I can say that FOSS programmers often bend over backwards to package things nicely, but are often rebuffed by non-programmers if the interface is not 100% to their liking.

      There is a disconnect, but IME it comes from people who think that being a user entitles them to sit back and wait for manna to drop from heaven. The bottom line is simply this: If you're going to work in FOSS, then you have to get your hands dirty. This almost necessarily means learning a little about areas that are not your forte. In order for there to be reasonable cooperation, we need to speak the same language. In the Perl community especially, there is a real desire to learn new things and share knowledge, but if designers et alia aren't willing to learn at least a little Perl, then there's not much to be done.

      "Don't make me look at code" is, unfortunately, not often a valid condition for any FOSS participant, regardless of their other talents.

      --
      Crumb's Corollary: Never bring a knife to a bun fight.
    6. Re:These charts look like shit by MikeBabcock · · Score: 3, Insightful

      That's the stupidest comment that gets repeated about all sorts of things in Open Source. There are people who can document, who can theorize and who can draw much better than they can code. If coders and those who can't code but have potential for contribution would communicate, we'd end up with better software. Software isn't just code, sorry to say. Yes yes, "show me the code" is a great line, and wrong for almost everything outside libraries and kernel space (and even then, some documentation writers, theorists and idea people should be involved more than they are by the coders).

      --
      - Michael T. Babcock (Yes, I blog)
  2. wow! by jdunn14 · · Score: 2, Funny

    With a general purpose language tied to a drawing library I can make custom graphics? Holy crap, who would have thought. 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?

    1. 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.
    2. Re:wow! by choongiri · · Score: 2, Interesting

      > Anyone have better solutions?

      Yes.

      eZComponents Graph, from the developers of the eZpublish CMS. It's FLOSS, easy to use, and works very well for some automatically generated graphs I made that needed to update every week.

    3. Re:wow! by Andy+Dodd · · Score: 4, Interesting

      octave + gnuplot + LaTeX = absolutely beautiful plots in anything I submitted (homework assignments, term papers) in grad school.

      To get you started (there could be errors here, I'm doing this from memory, but Octave code something similar to this:

      plot blah
      hold on
      plot something
      plot otherstuff
      hold off

      gset term postscript eps color 22
      gset output someplot.eps

      replot

      gset output foo %bad shit happens to your plot output if you don't change the output file when setting the term back to X11
      gset term x11

      Would do the following:
      Plot multiple things in a plot to the screen
      Output that plot to an EPS file
      Reset the output so the next plot would go back to the screen

      You could then run the .eps files through epstopdf, write some document in LaTeX that included your plots by their basename (i.e. without the .pdf extension in the document), and use pdflatex to generate a nice PDF file complete with clickable cross references

      (There are a lot of details I'm not mentioning here of course, unfortunately there really isn't any single good central HOWTO for doing all sorts of useful stuff in LaTeX.)

      --
      retrorocket.o not found, launch anyway?
    4. Re:wow! by T-Ranger · · Score: 2, Informative

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

    5. Re:wow! by zippthorne · · Score: 2, Interesting

      Indeed. Also, Matlab runs on linux, and has latex pretty-print modes. So you don't have to get all confused learning the quirky similarities between Octave and Matlab is you don't want to.

      And LyX is very convenient. Especially for typesetting those pesky equations. Much less flaky than MS Office, or even OO.org. In fact, I'd classify its equation modes as not flaky at all. Of course, it's convenient that anything they don't support can simply be escaped and typed in pure latex...

      My favorite thing about LyX is that even if you have a lot of pictures and included files, when you insert new elements, old elements (like graphics or text-boxes) don't go flying all over the document depending on how you've anchored them.

      --
      Can you be Even More Awesome?!
  3. So close by niceone · · Score: 5, Funny

    Ah, the summary was so close to getting the words 'perl' and 'readable' in the same sentence (possibly for the first time), but just couldn't quite pull it off.

    1. Re:So close by 26199 · · Score: 2, Insightful

      Heh. Congrats on being modded 'interesting' for that.

      Any chance I can get funny moderation? Or insightful, maybe?

    2. Re:So close by $RANDOMLUSER · · Score: 2, Funny

      Of course, "readable" was referring to the charts, not the Perl, which, as everyone knows, is write-only.

      --
      No folly is more costly than the folly of intolerant idealism. - Winston Churchill
  4. 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.

  5. Re:Don't get it.. by Hijacked+Public · · Score: 4, Funny

    I don't know man, they have a donut chart on there with some pretty serious graphics laid into it. That beats most other articles with their plain Jane donut charts, these ones have upper management written all over them.

    Maybe they should email a link to Edward Tufte...amybe he'll be insterested. Data graphic geniuses these folks.

    --
    "Sacrifice for the good of The State" - The State
  6. ChartDirector by rishistar · · Score: 2, Interesting

    I was looking for graphing and charting stuff last year. The only thing I found at the time was ChartDirector. There have been a couple of other open source ones posted above that I may investigate in future, but finding this was what I needed at the time.

    --
    Professor Karmadillo Songs of Science
  7. We all know... by ytm · · Score: 5, Funny

    ...that pie charts are evil. However there are exceptions, like this one: http://themot.org/gallery/d/58721-1/pacmanchart.pn g. Most informative.

  8. Re:Don't get it.. by Bodero · · Score: 2, Interesting

    Agreed. I had the same problem not too long ago about making dynamic charts that look professional.

    My solution was to use Perl and Win32::OLE to interface with Excel 2003 using VBA scripting within Perl. Sure, it's a Windows-only solution, and it's not open source, but it was an intranet problem that needed to be solved.

  9. The right tool for the right job by espressojim · · Score: 4, Insightful

    Remember how programmers always talk about using the right tool for the right job?

    If you want to do something like graphing, then why not learn a language like R, where you can easily and interactively create amazing visuals in very little time? I write code in Java, python, bash, and interact with Oracle and MySQL database. R fits in as a nice way to visualize data, and it's very easy to script up solutions that you can plug into your programming pipeline.

    Check out http://addictedtor.free.fr/graphiques/index.php for examples (with source code)

    1. Re:The right tool for the right job by suv4x4 · · Score: 3, Interesting

      The examples I can find in flash are 1-2 liners in R. Seriously, plotting a bar graph or pie graph or scatter plot is 2 lines (1 line input the data, 1 line to plot the graph.) Now, do something complicated and interesting as shown above. Do a multi-dimensonal plot. Do a box and whiskers plot (again, a 1 liner in R) that calculates medians, quartiles, etc.

      Lookup Flex Charts. An open-source Flash library for rendering charts, by Adobe.

      It can renders charts if you just feed it the data (in XML format) and what chart type you want.

  10. Yes, actually. by Erris · · Score: 2

    With a general purpose language tied to a drawing library I can make custom graphics? Holy crap, who would have thought.

    LibGD was made for this but does more now. There are lots of applications to do the same but "use libGD" is a good tip for people who want to make dynamic images and graphs for web pages from data.

    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.

    gnuplot is very powerful. It has fitting with regression analysis, reports reduced chi squared and other math muscle stuff for papers all from text files.

    Gnumeric is a good replacement for excel. It's resource light and the math is correct. It does simple graphs for papers and such.

    --
    DMCA, Hollings, Palladium. What might have sounded like paranoia is now common sense.
  11. Ruby / Gruff by carlivar · · Score: 2, Informative

    Or use Ruby with Gruff.

    --
    Vote Libertarian
  12. Re:Don't get it.. by vk2 · · Score: 2, Interesting

    Have you seen this? http://www.advsofteng.com/

    --
    No Sig for you.!
  13. SVG and ImageMagick by Ysangkok · · Score: 2, Insightful

    I make my PHP scripts output SVG. I feed it to ImageMagick's "convert", and then outputs it to the user.

  14. Re:Killing an ant with a thermonuclear bomb... by Bodrius · · Score: 4, Funny

    Yeah, it does seem a bit overkill.

    If you're organization is so dynamic that your org. chart NEEDs to be generated at runtime by a script on your web server, then maybe writing perl scripts to auto-generate org charts shouldn't be your highest priority.

    --
    Freedom is the freedom to say 2+2=4, everything else follows...
  15. These charts look like shit? No they don't. by matt+me · · Score: 2, Interesting

    Those charts look pretty hot to me. Did you look at the chart in the page? http://www-128.ibm.com/developerworks/opensource/l ibrary/os-perlgdchart/pie_step1_step2.gif
    ). Anti-aliased lines and text :]

    Let's compare this to what I'd get if I asked most professionals for a chart. (These were the first ones from google). The lack of anti-aliasing hurts one's eye, these all look like they're from 1995.
    http://support.alphasoftware.com/images/XD_Interac tive_Pie_Chart.gif
    http://msdn2.microsoft.com/en-us/library/aa192481. odc_vststockallocation2003_fig03(en-us,office.11). gif
    (the second one is 3d)

    And in response to your comment
    > When will open source advocates learn to delegate the graphic design aspect of their work to professionals? if only the programming types in charge of these projects would admit they're better at making code than graphics.
    You seem to have missed the point. The article is about free software that can be used by professional and non-professional alike to create some hot graphics. Perhaps you're referring to the ugliness of the original tux logo? It's not 1995, and developers aren't resigned to producing their own graphics. If you look all free software houses pushing their brand use professional designers. Think of the firefox logo (2004)
    http://www.hicksdesign.co.uk/journal/branding-fire fox
    or of ubuntu and gnome's curves, and check out the tango project http://tango.freedesktop.org/
    Desktop linux has never looked so sexy.

    Why so sour, AC?

  16. 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.

  17. 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
  18. Ah, charts in Perl... by glwtta · · Score: 4, Interesting

    I do most of my work in Perl, and the lack of a good chart package has been annoying for a very long time. GD::Graph will give you very basic (and not terribly ugly) line and bar charts relatively quickly, but that's about it; it's missing even rudimentary features that make it less than useful (eg error bars).

    There just isn't a general purpose charting package for Perl that would even come close to JFreeChart. 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).

    So, if you want publication quality charts you basically still have to learn gnuplot, which is great, but sometimes just a little too involved.

    At least this thread gives a nice summary of what the other languages have to offer: the PHP and Ruby packages aren't faring any better, but Python's matplotlib looks freaking beautiful.

    --
    sic transit gloria mundi
    1. 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.
  19. Edward Tufte weeps... by xixax · · Score: 2, Insightful

    Judging by the examples, this brings the readability of Perl into graphs.

    I think I can hear Edward Tufte weeping...

    And the only chart they implement is the pie chart:

    http://www.usf.uni-osnabrueck.de/~breiter/tools/pi echart/warning.en.html

    Xix.

    --
    "Everything is adjustable, provided you have the right tools"