Forgot your password?
typodupeerror

Custom Charts w/ Perl and GD 112

Posted by CmdrTaco
from the make-a-pac-man-pie-chart-now dept.
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."
This discussion has been archived. No new comments can be posted.

Custom Charts w/ Perl and GD

Comments Filter:
  • by Anonymous Coward
    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.
    • Re: (Score:3, Funny)

      by Solra Bizna (716281)

      I'm better at making code than graphics [deviantart.com].

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

      -:sigma.SB

    • by dbcad7 (771464) on Sunday April 29, 2007 @01:22PM (#18919531)
      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.

    • by dodobh (65811) on Sunday April 29, 2007 @01:37PM (#18919643) Homepage
      The code is out there. Whenever the graphics folks want to start contributing, they can.
      • The code is out there. Whenever the graphics folks want to start contributing, they can.

        I think this is indicative of a disconnect.

        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 bet
        • by grcumb (781340) on Sunday April 29, 2007 @04:43PM (#18920969) Homepage Journal

          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.

          • I have done a lot of software design and implementation and a lot of UI design and implementation but I tend to agree with the sentiment that programmers shouldn't be doing UI work - the results usually leave a lot to be desired and to see why you only have to read /. for a while to get a sample of the attitude that many programmers have toward users. I also have problems with the other side, as the parent says, waiting for manna to drop from heaven.

            But graphic artists can contribute without knowing an

          • by dbIII (701233)
            Sliding a bit off topic here but gimp is a prime example. It appears to be great stuff for people putting together web page graphics on a platform where you have multiple screens (not really sure - only ever did that on a small scale) but print graphics designers don't go past saying "it's not photoshop - come back when it's a slavish photoshop clone" so gimp gets what the developers think might be useful and have to play a guessing game. The "don't ask me for what features I need just give me photoshop"
            • by avronius (689343) *
              I don't believe that you should have been flamed - Photoshop has had undo since at least 1991 [this is when I started using 2.0]. Not sure if was there an undo prior to that, but I doubt that you would have been discussing the GIMP back then ;)

              In all fairness, there wasn't a multiple level undo until much later [version 5 or so], so you would have needed to save prior to doing multiple changes.
          • by lpq (583377)

            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.

            If there is any question in people's mind about whether or not Linux or FOSS software is is ready for the average user's desktop, maybe it can be answered here. Users can't expect to just get software and have it work. Before they can do their work (or play,

            • by chromatic (9471)

              That so many in FOSS can't see the inefficiency of requiring all users, to be some level of developer, on every tool they use...

              Besides you, who said anything about requiring any users to become developers? Contributors, yes. Developers, no.

            • by avronius (689343) *

              It's like requiring users to be car mechanics in order to drive an FOSS car.

              I would think that it's more like belonging to a focus group discussing a concept car. The developers need [useful] feedback.

              Saying, "I hate it. What is it?" won't help. Saying, "I don't like having to go seven layers into a menu to do this common procedure" will help.

              That so many in FOSS can't see the inefficiency of requiring all users, to be some level of developer, on every tool they use

              Have you ever made a recommendation for process improvement? Have you ever contributed to a project that required your special skills or unique insight? Have you been passed up for a promotion based on your recommendations or insight on a pr

              • by lpq (583377)

                FOSS is not for everyone.
                Many people are willing to invest cash for a product that "just works" and requires no investment of time to aid in development.
                Many people are willing to invest time for a product that requires no financial outlay to compensate for development.

                This is, basically, my point. When will "Linux" or "FOSS" (the terms are both vaguely defined) be ready for the corporate or home desktop? At that point, you are mostly talking _users_ of computers that know little or nothing about computer

        • by dodobh (65811)
          The designers sure can offer suggestions and help. You don't have to write code to contribute (but it sure helps).
      • by MikeBabcock (65886) <mtb-slashdot@mikebabcock.ca> on Sunday April 29, 2007 @05:26PM (#18921295) Homepage Journal
        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).
    • 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).

    • by hxnwix (652290)
      Hey, don't let us stop you.
    • 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 [ibm.com]
      ). 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 [alphasoftware.com]
      http://msdn2.microsoft.com/en-us/library/aa [microsoft.com]
    • When will open source advocates learn to delegate the graphic design aspect of their work to professionals?

      My partner, a graphic designer, says the same thing about the artwork in the Dungeons and Dragons manuals... I guess geeks everywhere and in every age think they can draw or something...
    • These are development tools and like it or not, developers are often asked to write visual applications, where the emphasis is on content and not beauty. I've used both perl and GD in the financial sector to plot curves, where people only wanted a visualisation of data and not a graphically designed splash of paint. I give a thumbs up to libgd.
  • wow! (Score:3, Funny)

    by jdunn14 (455930) <jdunn&iguanaworks,net> on Sunday April 29, 2007 @12:57PM (#18919393) Homepage
    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?
    • Re:wow! (Score:5, Informative)

      by Coryoth (254751) on Sunday April 29, 2007 @01:29PM (#18919587) Homepage Journal

      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] [wikipedia.org], [2] [wikipedia.org], [3] [wikipedia.org] [4] [wikipedia.org] (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 [sourceforge.net] which is actually pretty versatile, and produces good looking plots. There's also PyX [sourceforge.net] 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.
      • by atrus (73476)
        I agree, GNUPlot is quite capable.
        • Re: (Score:3, Informative)

          by T-Ranger (10520)
          Its not GNUPlot. Gnuplot, or gnuplot, sure. But it has exactly nothing to do with GNU.
      • Re:wow! (Score:5, Interesting)

        by Andy Dodd (701) <atd7@NosPaM.cornell.edu> on Sunday April 29, 2007 @08:50PM (#18922685) Homepage
        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.)
        • Re: (Score:3, Interesting)

          by zippthorne (748122)
          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 abou
        • Just some weeks ago I was looking for a way to make some plots. I usually use gnuplot but as far as I could see it seemed uanble to do bar plots, pie plots, discrete 3d plots (this is, make Z axxis a set of items instead of a continuos range), radar plots, bubble etc. It seems it is only possible to do point and line plots.

          I looked for some tutorials on the web to do bar plots but they consisted in half assed hacks (translate the data point, surround it by a bounding box etc etc) which is too much work for
      • If you really want the flashing lights, swirling thingies or generally make your charts management friendly, I'd recommend this library [maani.us] for PHP (or for Perl use the SWF::Chart [cpan.org] wrapper).

        With enough animated transitions to last you a good 3-4 promotions you should be set :)
      • It's scriptable, can do some calculations, does time series, has multiple outputs and is cross platfor.

        My intro was on DOS plotting time series data to screen or an Epson MX80 printer.
        I used Excel (4) which had serious issues with time series and Kaleidagraph on a Mac.

        It's always there on Unix and I think there is/was a macintosh version.

        gnuplot is timeless.

        That said, for long term time series with thousands of data points, I like RRDtool. It deals well with consolidating the data.
      • Nice examples! However, I couldn't help but notice that there is a typographical error in the first example you posted a link for [wikipedia.org]. I believe the word you wanted was "Antarctica" but the graph instead shows "Antartica" (it's missing a "c").

        And now back to your regularly scheduled program...
    • 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 powe

    • by ytm (892332)
      I have to use Excel at work for presentation because we need dynamic charts based on pivot tables. For inspiration I recommend these pages [peltiertech.com]. Most of these methods show ways around Excel limitations and twisted paths to display your data right.

      For paper presentation I'd go with gnuplot. It requires some work to get it right, but results are impressive and can be easily embedded in LaTeX environment.

      As for TFA, I would think that with a programming language and graphics library we would be able to see so
    • Re: (Score:2, Interesting)

      by choongiri (840652)

      > Anyone have better solutions?

      Yes.

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

    • by Noksagt (69097)
      Grace [weizmann.ac.il] is an excellent free/open source 2D plotting program. It is in Motif, so some might call it "ugly," but I run it on Windows (it is packaged in cygwin), OS X, and linux. It is the most versatile F/OSS package I know of--both in terms of features & in terms of user interaction. In addition to the GUI (which many of the programs you list lack), you can use a command line interface or bindings [weizmann.ac.il] for python, perl, fortran, C++, OCaml, octave, rlab, etc.
  • So close (Score:5, Funny)

    by niceone (992278) * on Sunday April 29, 2007 @01:03PM (#18919437) Journal
    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.
  • 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
    And if you really considered yourself a Perl programmer, you'd be able to do it all in one line of code.
    • by 26199 (577806) *

      There's always Acme::Bleach [cpan.org] if you're having trouble making it a one-liner.

    • And if you really considered yourself a Perl programmer, you'd be able to do it all in one line of code.

      I wasn't under the impression that Perl *required* newlines anywhere.. can't you just take an existing perl script, delete all newlines and it will compile/run just as before?
  • by MarkEst1973 (769601) on Sunday April 29, 2007 @01:16PM (#18919507)
    ... there's matplotlib [sourceforge.net] and there's reportlab [reportlab.org] 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.
  • ChartDirector (Score:3, Interesting)

    by rishistar (662278) on Sunday April 29, 2007 @01:44PM (#18919683) Homepage
    I was looking for graphing and charting stuff last year. The only thing I found at the time was ChartDirector [advsofteng.com]. 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.
    • We use R. I t produces visually appealing neat & clean graphics. My only bugbear is that the raster renders are external syscalls and often handle things like fonts and anti-aliasing poorly. We weer also looking at Rserv as a graphing service rather than invoking an R instance each time we want a graph. http://www.r-project.org/ [r-project.org]

      Xix.
    • by Basje (26968)
      I second that. I've dabbled with perl and GD and several other graphics modules for perl, but ChartDirector is the only one to easily produce good looking, anti aliased graphs. So we used that.

      But our product is commercial. I would really love to see a solution for my OS projects. The aa in the article is horrible, GD just doesn't cut it.
  • by ytm (892332) on Sunday April 29, 2007 @01:45PM (#18919687) Homepage
    ...that pie charts are evil. However there are exceptions, like this one: http://themot.org/gallery/d/58721-1/pacmanchart.pn g [themot.org]. Most informative.
  • In case you missed the memo [themot.org].
  • by espressojim (224775) <eris@NOsPam.tarogue.net> on Sunday April 29, 2007 @01:55PM (#18919761)
    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 [addictedtor.free.fr] for examples (with source code)

    • by suv4x4 (956391)
      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.


      There's Flash for Linux/Windows/Mac, and it can ren
      • Yeah. You can render data. But you need to do analysis to determine how to render data. It's more complicated than picking where to draw each pixel. I see there are tools to export Excel into flash, what's the big deal there?

        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
        • by suv4x4 (956391) on Sunday April 29, 2007 @04:01PM (#18920611)
          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.
    • by hey! (33014)
      The right tool for the job is often the one you have in your toolbox that will do the trick.

      Yes, you don't use your nice new wood chisel to pry the lid off a can of paint. But you might use it instead of driving down to the home depot to get a specialized router attachment, if you can do the job with the chisel in less time than the drive would take. If you plan on doing this operation hundreds of times over the next few months, then by all means drive down to the store and get the specialized attachment.
    • gnuplot works for me.
  • Ruby / Gruff (Score:3, Informative)

    by carlivar (119811) on Sunday April 29, 2007 @02:01PM (#18919801)
    Or use Ruby [ruby-lang.org] with Gruff [nubyonrails.com].
  • I've been using Charts::* for my needs, these look much better. No functionality improvement, but looking better is sometimes a criteria.
  • by Ysangkok (913107)
    I make my PHP scripts output SVG. I feed it to ImageMagick's "convert", and then outputs it to the user.
  • Perl and GD. That's how charting is done in Bugzilla. Can't say it's superior, but it fits the needs. If I ever write something in Perl that would require charting then I might resort to GD.

    For now, I'll avoid Perl if I can.
  • Every time you say "Goddammit!" when you try to run it? I gotta see what happens with this
  • using Octave or SciLab.
  • Use JPGraph instead (Score:3, Informative)

    by yahyamf (751776) * on Sunday April 29, 2007 @04:37PM (#18920917)
    JPGraph [aditus.nu] 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.

  • A year ago I went looking for code to draw Gantt like charts (for project scheduling, not the whole kebab).
    I ended up rolling my own in GD with perl (making a wxPerl gui app). Reading this made me think (why doesn't he put it on CPAN) and then my next thought was (maybe I should put my own code up there before talking).

    Not sure when I'll have time but anyway keep up the good work.

    For everyone talking about design, yes it would not be a bad thing to take a first step to seeking designers interested in workin
  • TFA is hardly news, but whatever... here are some of my dynamic plots with GD::Graph. Comments welcome.

    They're quite pretty in my opinion, but having read this thread, I realised they are not anti-aliased and that's not easy to do in GD::Graph at the moment (while drawing the lines, at least - I just read there is a trick one can do with resampling a 4x image).

    Also, there's a problem with the lines not really being the desired thickness perpendicular to the directi

  • by glwtta (532858) on Sunday April 29, 2007 @07:10PM (#18922085) Homepage
    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 [jfree.org]. Grace [weizmann.ac.il] 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 [aditus.nu] and Ruby [nubyonrails.com] packages aren't faring any better, but Python's matplotlib [sourceforge.net] looks freaking beautiful.
    • Re: (Score:3, Informative)

      by Noksagt (69097)

      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 [cpan.org] nor Chart::Graph::Xmgrace [caida.org] seem TOO obscure.

      The command line interface of grace isn't terrible--it is MUCH mo

  • I used to use GD::Graph on my Windows-based system, but then the PPMs never got updated for the latest versions of ActivePerl.

    For the longest time I have been without it since I updated ActivePerl, and there was no PPM available for GD::Graph on the ActiveState repository

    http://ppm.activestate.com/BuildStatus/5.8-G.html [activestate.com]

    After looking at the site, I found the link at the bottom of this page [activestate.com] that says you can install GD from Univ of Winnipeg, and I was able to install GD Graph from their repository.
  • by Anonymous Coward
    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 [ajaxian.com]
    I think I've seen a live charting demo on Dojo's official website, but it seems to be no longer there.

    WT Toolkit [sourceforge.net]
    This one seems to be a new project, judging from the activity charts on their SourceForge page [sourceforge.net]. The way they can draw 3D charts (like, pie cha
  • [rant]I would be much more happy with AIX if they included a recent version of GD. As it stands, the version available for AIX 5.3 is so old it doesn't even have GIF support, and that makes a bunch of applications angry. Bugzilla for one doesn't like the version of GD that's available on AIX. I even tried compiling it myself, but ran into really weird font errors. Grrrr....sometimes I don't like AIX. [/rant]
    • by Intron (870560)
      If you have the IBM-compiled perl, you need the IBM compiler. If you only have gcc, you are better off recompiling perl if you want to add cpan modules.
      • by Corrado (64013)
        Yup, I re-compiled Perl with GCC and everything. Blech - I wish IBM would get their stuff straight! :/

UNIX was half a billion (500000000) seconds old on Tue Nov 5 00:53:20 1985 GMT (measuring since the time(2) epoch). -- Andy Tannenbaum

Working...