[tpm] GD::Graph question

Jim Harris ja_harris at rogers.com
Tue Aug 26 08:15:10 PDT 2008


#!/usr/bin/perl

use strict;
use GD::Graph::area;
#use GD::Graph::lines;
use Carp;
use Time::Local;

umask 0222;

#
#       set dimensions for graphics
#
our ($x,$y) =(500, 210);


open CONFIG, $configfile
        or die "can't open $configfile: $!";

our %LOCATION;
our %TTY;
while (<CONFIG>) {
        if (/^(\d) (\S+) (\S.*)/) {
                $LOCATION{$1} = $2;
                $TTY{$1}      = $3;
        }
}



my (@ttyi, at ttyt, at both, at label);
#       $ttyi[$x] = $y; and so on
#       $both[] = sum of tty's on the device, there's always two on each device



my @data;
my @legend;
my @colors;

if ($TTY{$switch} =~ /ttyt/) {
        @data = (
                [ @label ],
                [ @both  ],
                [ @ttyt  ],
        );
        @legend = (
                'ttyi',
                'ttyt',
        );
        @colors = (
                'red',
                'blue',
                'cyan',
        );
}
else {
        die "cannot determine proper TTYs";
}


$graph = GD::Graph::area->new($x,$y);



$graph->set(


#       x_label         => $dateLabel,
        x_label         => "$title   $dateLabel  $weekday[$wday]",
        #x_label                => '',
        x_label_skip    => 6 * 3,
        x_tick_offset   => 6 * 3,
#       x_all_ticks     => 1,

#       two_axes        => 1,

        y_label => 'completions / 10 minutes',
        y_min_value     =>  0,
        y_max_value     => $speed,
        y_tick_number   =>  $speed/20,
        y_label_skip    => 2,


) or die $graph->error;

$graph->set( dclrs => [ @colors ] );
$graph->set_legend(@legend);
$graph->set(
        legend_placement        => 'RT',
);

my $gd = $graph->plot(\@data) or die $graph->error;


open (IMG, '>', $png) or die "can't open '$png': $!";
binmode IMG;
print IMG $gd->png;
close IMG;

exit;




--- On Mon, 8/25/08, Mark Fowle <mfowle at navicominc.com> wrote:
From: Mark Fowle <mfowle at navicominc.com>
Subject: Re: [tpm] GD::Graph question
To: "Madison Kelly" <linux at alteeve.com>
Cc: "tpm" <tpm at to.pm.org>
Received: Monday, August 25, 2008, 8:33 PM

If SVG is OK for you (client browser support wise)
I'd go one of two routes:
1. draw a SVG graph with the first dataset and a second graph with
almost everything 0% opaque so only the line shows up.

2. get into SVG Graph and change the code so y scale can be a scalar or
an array. Then adjust the scaling code to use the array element
corresponding to the dataset.



Idea 2 is probably implementable in GD Graph.

Mark Fowle


-----Original Message-----
From: toronto-pm-bounces+mfowle=navicominc.com at pm.org
[mailto:toronto-pm-bounces+mfowle=navicominc.com at pm.org] On Behalf Of
Madison Kelly
Sent: Monday, August 25, 2008 4:26 PM
To: Scott Elcomb
Cc: tpm
Subject: Re: [tpm] GD::Graph question

Scott Elcomb wrote:
> On Sun, Aug 24, 2008 at 7:47 PM, Alex Beamish <talexb at gmail.com>
wrote:
>> My first Perl gig ten years ago was doing graphs, and I used Gnuplot
>> quite successfully to draw graphs-- it's a very flexible package.
> 
> Hmm.  My first gig involved writing wrappers around GD::Graph.  Since
> it was "my first gig" the code in my ... um... uh... library
"SAL"
> definitely reflects that.  One day I might even get around to
> modernizing it and making it useful.
> 
> Unfortunately (fortunately?) I never had to deal with this particular
> problem.  Madison, if you find a solution could I ask that you post it
> up for us?
> 
> Many thanks.
> - Scott.

At this point, I've moved on from GD::Graph and am playing with 
SVG::TT::Graph. I'm having mixed luck; It seems like a much more 
flexible solution and I am getting cleaner graphs, but I have not yet 
been enable to figure out to create a dual Y-axis graph, assuming it is 
possible at all.

Once I figure something out I will indeed post it to the list "for 
posterity". :)

Madi
_______________________________________________
toronto-pm mailing list
toronto-pm at pm.org
http://mail.pm.org/mailman/listinfo/toronto-pm
_______________________________________________
toronto-pm mailing list
toronto-pm at pm.org
http://mail.pm.org/mailman/listinfo/toronto-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20080826/0aba0838/attachment.html>


More information about the toronto-pm mailing list