Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Charting Modules

by ptum (Priest)
on Nov 14, 2005 at 19:03 UTC ( #508378=perlquestion: print w/ replies, xml ) Need Help??
ptum has asked for the wisdom of the Perl Monks concerning the following question:

It has been some time since I last needed to dynamically create a bar or line chart from an arbitrary data source (in my case a database of network configuration events). Several years back I used Martien Verbruggen's GIFgraph module -- I see he has moved on to GD::Graph. Has a clear leader in terms of usability and attractive functionality emerged among the CPAN graph and chart modules?

UPDATE: Thanks to all those who responded; I checked out GD::Graph3d and found it very much to my liking. I decided to rebuild libgd on my Solaris 5.9 system to include the libpng and FreeType libraries, and I had quite a bit of difficulty before I realized that I needed to provide the LD_LIBRARY_PATH environment variable to my CGI script in order for it to find the proper GD libraries to produce the PNG images. I hadn't realized that environment variables need to be explicitly passed or set within Apache http://httpd.apache.org/docs/1.3/env.html. I ended up with dynamically-generated PNG images with support for TrueType fonts, which pleases me greatly. Here's a simple test script that produces a 3d bar, 3d line and pie chart from sample data, if anyone is interested:
#!/usr/local/bin/perl -w use GD::Graph::bars3d; use GD::Graph::lines3d; use GD::Graph::pie3d; use CGI qw/:standard :html3 center/; use CGI::Carp qw(fatalsToBrowser); use strict; print header; print start_html(-title=>"3D Graph Test"); my @data = ( ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], [ 1203, 3500, 3973, 2859, 3012, 3423, 1230], [ 819, 2500, 4901, 429, 1604, 2199, 700], [ 4412, 1500, 2211, 1394, 4501, 2290, 50], ); my @graphs = (); my $width=300; my $height=200; print "<center><table border=0 cellpadding=10 cellspacing=10><tr>"; $graphs[0] = new GD::Graph::bars3d( $width, $height ); $graphs[1] = new GD::Graph::lines3d( $width, $height ); $graphs[2] = new GD::Graph::pie3d( $width, $height ); $graphs[0]->set ( bar_depth => 10, bar_spacing => 10, overwrite => 2, cumulate => 1, shading => 1 ); $graphs[1]->set ( line_depth => 5, shading => 3 ); for (my $i=0;$i<3;$i++) { $graphs[$i]->set ( x_label => 'Day of the week', y_label => 'Number of hits', zero_axis => 1, box_axis => 0, title => 'Daily Summary of Web Site', ); $graphs[$i]->set_legend("Frank", "Bob", "Sue"); $graphs[$i]->set_title_font('/usr/openwin/lib/locale/iso_8859_13/X +11/fonts/TrueType/LucidaTypewriterBoldOblique.ttf', 8+$i*2); $graphs[$i]->set_legend_font(GD::Text::gdTinyFont); my $timeval = time() + $i; my $gd = $graphs[$i]->plot( \@data ); my $image_stream = $gd->png(); unless (open(GRAPH,">/up/web/data/testgraph${timeval}.png")) { die "Can't open /up/web/data/testgraph${timeval}.png: $!"; } print GRAPH $image_stream; close(GRAPH); print qq|<td><img src="../data/testgraph${timeval}.png" alt="Test +chart"></td>|; } print "</tr></table></center>"; print end_html();

Comment on Charting Modules
Download Code
Re: Charting Modules
by samtregar (Abbot) on Nov 14, 2005 at 19:29 UTC
    Last time I looked GD::Graph was still king. I'm using GD::Graph3d, which adds a moderately flashy 3d effect.

    Some people seem to like DBD::Chart, but frankly, I think they're nuts. The interface is the craziest thing since XSLT.

    -sam

Re: Charting Modules
by BerntB (Deacon) on Nov 14, 2005 at 19:46 UTC
    Well, both GD and GD::Graph is on the Phalanx top 100.

    Without knowing much about any kind of graphics (-: except language :-), that is probably a hint.

    (Update: English isn't my native language. but I believe an idiom for curses is "graphical language"? Is the name of the curses lib a joke, since there are no graphics in the curses lib? But it is probably older than unix and graphics became mainstream.)

      I believe you're refering to the Curses library which was definitely created before graphical user interfaces were common. Although I've only just started to search, I've not found a good resource discussing the origin of the name "curses". I suspect it was probably a combination of a playing with the words "cursor" and very likely the amount of frustration, thus "cursing", done when trying to write any sort of "graphical interface" back in those days.

      So, while it's definitely not a joke in the strict sense you meant, it easily could be a bit of play on words.

      Back when the curses library was all the rage, "graphics" simulated with text characters was a semi-respected medium.

      -Scott

        Thanks for the answer. I am old enought to have written a bit of code with it, just prior to the form tag.

        But not much code, since already the curses lib was stretching my talents for layouts and my aesthetical eye. :-)

        'curses' was quite neat to use and if that resulted in cursing, I hope the responsible programmer never used gui libs!

        (-: And, no, it didn't hurt my eye when my aesthetical eye was stretched, but the viewers' eyes. Should lay off the language jokes when I am on shaky idiomatic ground. :-)

Re: Charting Modules
by diotalevi (Canon) on Nov 14, 2005 at 20:28 UTC
    In addition to CPAN modules, check out gnuplot.

      In addition to CPAN modules, check out gnuplot

      For which there is a CPAN module: Term::Gnuplot :)

      regards,
      tomte


      An intellectual is someone whose mind watches itself.
      -- Albert Camus

Re: Charting Modules
by dragonchild (Archbishop) on Nov 15, 2005 at 00:45 UTC
    I wrote Graph::Template to wrap GD::Graph with the same API as HTML::Template, Excel::Template, and PDF::Template, but it's in an incomplete state. If you want, you can take it over from me ...

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Charting Modules
by davorg (Chancellor) on Nov 15, 2005 at 10:54 UTC

    I like SVG::TT::Graph. Of course, you'll probably need to put in an extra step to convert the SVG output into a PNG. But the graphs it draws are just luvverly.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Charting Modules
by zentara (Archbishop) on Nov 15, 2005 at 12:56 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://508378]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-08-30 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls