http://qs1969.pair.com?node_id=731584

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

Hello everyone,

I have a whole lot of Perl scripts running at work monitoring and reporting on what's happening in our Active Directory and Exchange. One of them reports mailbox sizes every day. Now Instead of checking the report of a given user/mailbox from a month ago I would like to draw a graphical chart from this data, so I could basically easily see how much (if any) that particular mailbox has been increasing in size since x number of days ago.

I reckon some one has already built this kind of module that I could use, but I'm a bit confused on how to start searching for it using CPAN. I think passing numerical values from my script to the module should do the job, because it is basically just a matter of knowing the lowest and highest point and on what intervals were those values calculated?

I'm looking for way to generate charts in well-known picture formats like JPEG, GIF or PNG and then send those pictures to myself using E-mail. Any help would be much appreciated if some one has been in a similar situation before.

Replies are listed 'Best First'.
Re: Perl module for chart drawing?
by zentara (Archbishop) on Dec 19, 2008 at 16:41 UTC
    Sounds like GD's bar graph would work. Search groups.google and google for examples. Here is a little starter script, mailling it to yourself is a different problem.
    #!/usr/bin/perl use GD::Graph::bars; @A = qw(-5 -4 -3 -2 -1 0 1 2 3 4 5 ); @B = qw(-6 -4 -2 0 2 4 6); @C = qw(1 2 3 4 5); @D = qw(4 5 6 7); @E = qw(-2 -4 -6 0 2 4 6 8); @datacolors = qw(blue green cyan pink yellow); my @data = ([@A],[@B],[@C],[@D],[@E]); my $graph = GD::Graph::bars->new(600,400); $graph->set( transparent => '0', x_label => 'A', y_label => 'B', title => 'A for B', dclrs => [ @datacolors ] ); open(IMG, ">$0.png"); binmode IMG; my $gd = $graph->plot(\@data); print IMG $gd->png; close IMG;

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Thank you! I'll try to use that snippet as a grounding for my own code. Thing is that I'm not really sure of what kind of data should the graphical representation contain, because when I start to play around with the idea so many different possibilities come to mind. But then again, that's for me to decide and tinker with :)
        Yeah, sleep on it for a few days, it saves rewrites later when you realize there is a better way. But then again, you often don't see the need for a better way, until you jump into the code and start hacking.

        I'm not really a human, but I play one on earth Remember How Lucky You Are
Re: Perl module for chart drawing?
by samtregar (Abbot) on Dec 19, 2008 at 16:49 UTC
    Definitely consider using Google Charts. It's so much easier than coding up custom charts in Perl (and yes, I've tried all the relevant CPAN modules) and the results are prettier too.

    -sam

      True, but no SVG output.

      I looked at Google Charts a while ago and while the results are some of the more attractive out there and the API is really nice to use. I'm just not comfortable handing off all the internal data I would like to graph to Google.

      Maybe one day they will release the renderer that we could run locally, until then its really something that pretty, but not useful.

Re: Perl module for chart drawing?
by planetscape (Chancellor) on Dec 20, 2008 at 08:30 UTC
Re: Perl module for chart drawing?
by linuxer (Curate) on Dec 19, 2008 at 18:00 UTC

    Maybe rrdtool is something you could use. (This was my first idea, as I read your message.)

    There are also some Modules available at CPAN for using rrd.

      If you decide to use rrdtool, make certain to check out Alex van den Bogaerdt's tutorials.

      RRDtool does not quite work the way people expect and these explanations do a good job of preparing you to expect the data you will get out of it. I've just recently been through this.

      G. Wade
Re: Perl module for chart drawing?
by hill (Sexton) on Dec 19, 2008 at 17:42 UTC
    Take a look at Chart Director. It's reasonably inexpensive, sold as a Perl module, and easy to use. Data is passed to it as array references with minimum, straight forward setup. Good looking output. Good customer service, too.
Re: Perl module for chart drawing?
by Anonymous Monk on Dec 19, 2008 at 16:40 UTC
Re: Perl module for chart drawing?
by lostjimmy (Chaplain) on Dec 19, 2008 at 18:33 UTC
    I've always found gnuplot to be very easy to use. You can pipe commands to it from Perl, but there is also Chart::Gnuplot, which I have never used.
      with above script, was testing module and facing error saying "sh: convert: command not found". Please help me .
        used script for test
        use Chart::Gnuplot::Pie; # Create the pie chart object my $chart = Chart::Gnuplot::Pie->new( output => "pie.png", title => "Sample Pie"); # Data set my $dataSet = Chart::Gnuplot::Pie::DataSet->new( data => [ ['Item 1', 7500], ['Item 2', 3500], ['Item 3', 2000], ['Item 4', 4500], ], ); # Plot a 2D pie chart $chart->plot2d($dataSet);
Re: Perl module for chart drawing?
by kevbot (Vicar) on Dec 01, 2015 at 08:08 UTC