Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: charting solution

Re: charting solution

From: Joe <nospam_at_joekaz.net>
Date: 15 Apr 2004 05:03:44 -0700
Message-ID: <b9c56449.0404150403.5f036824@posting.google.com>


"Housen" <rchin_at_panix.com> wrote in message news:<c5htbp$m4a$1_at_reader2.panix.com>...
> Thank you joe
> you wouldn't have the perl code around would you ?
> I'd appreciate if you can let me have it.
> thanks
> rchin_at_panix.com
>
>
> "Joe" <nospam_at_joekaz.net> wrote in message
> > I did something like that by writing a perl program using the module
> > GD:Graph. I wrote it as a generic graphing CGI program that gets
> > all of it's data as parameters.
> >
> > Then in my mod_plsql app, I do all the work to get the data, and
> > format it as a parameter string that my perl CGI script will accept.
> > Then still from mod_plsql, I create a web page where the IMG's tag
> > SRC is a call to the cgi graphic program.
> >
> > The result is that my mod_plsql program can produce any type of
> > graph that GD::Graph can.
> >

No problem. The complete perl code is below. It's a simple program, but could easily be customized for your own needs. This perl code should go in your webserver's cgi directory. It can go on any webserver, it doesn't have to be on the same webserver running 9ias mod_plsql, but it could be.

You could call this directly from a browser like:

http://yourwebserver.com/cgi-bin/simple_graph.pl?hd=2000-05,2000-06,2000-07,2000-08&d1=90,94,86,74&show_values=1

But what you really want to to is use it as IMG tag in another program. I integrate this with a 9ias mod_plsql app that I use to graph some Oracle capacity and performance data. From my plsql procedure, I query my tables to get the data, then format strings for the data and headings that I want to pass to the simple_graph cgi. For example - the whole trick is in the IMG tag:

...
htp.p ('<h1>Tablespace Growth</h1>);
htp.p ('show whatever else you need to show.<br>');

gr_ht := '300';
gr_wd := '600';
graph_type := 'lines';
in_sid := 'HR1';
show_values := 0;

htp.p ('<CENTER>');
  htp.p ('<img height='||gr_ht||'width='||gr_wd||

    ' src="' || cgi_path || 'simple_graph.pl' ||
    '?height='||gr_ht||'&width='||gr_wd||
    '&plot=' || graph_type ||
    '&hd=' || hd_string ||
    '&d1=' || d_string ||
    '&sid=' || in_sid ||
    '&show_values=' || show_values ||
    '">' );

  htp.p ('</CENTER>');
htp.p ('show more regular html if you want to ...'); ...

This is the CGI script simple_graph.pl:

#!/usr/local/bin/perl -w
#
# simple_graph.pl
#
# Runs as cgi, all args are optional, but it works better with some
data!
# Used to produce simple graphs in bar, area, lie or line/point format.
#

use strict;
use CGI qw/:standard/;
use GD::Graph::Data;
use GD::Graph::colour;
use GD;
use GD::Text;

my $HEIGHT = param('height') || '300';
my $WIDTH  = param('width')  || '400';
my $SID    = param('sid') || '?';
my $PLOT   = param('plot') || 'bars';

my @D1 = split /,/, (param('d1') || '0'); my @HD = split /,/, (param('hd') || '0'); my $SHOW_VALUES = param('show_values') || '0'; my $xskip = 0;

my $data = GD::Graph::Data->new([ \@HD, \@D1 ]) or die GD::Graph::Data->error;

# find max value, with some intelligent rounding up to the next big digit
#

my $max = (sort {$b<=>$a} @D1)[0];
if    ($max >10000) { $max = (int($max/10000)+1)*10000 }
elsif ($max >1000)  { $max = (int($max/1000)+1)*1000 }
elsif ($max >100)   { $max = (int($max/100)+1)*100 }
elsif ($max >10)    { $max = (int($max/10)+1)*10 }
else                { }

#
# Too many values on the x-axes is hard to read, so space out based on how
# many there are. This could be improved with recognition of whether we
# plotting weekly, monthly, or quarterly data. #
if ($#HD > 20) { $xskip = int($#HD/20) }

my $my_graph;
if ($PLOT eq 'area') {

    use GD::Graph::area;
    $my_graph = GD::Graph::area->new($WIDTH,$HEIGHT); } elsif ($PLOT eq 'lines') {

    use GD::Graph::lines;
    $my_graph = GD::Graph::lines->new($WIDTH,$HEIGHT); } elsif ($PLOT eq 'linespoints') {

    use GD::Graph::linespoints;
    $my_graph = GD::Graph::linespoints->new($WIDTH,$HEIGHT); } else {

    use GD::Graph::bars;
    $my_graph = GD::Graph::bars->new($WIDTH,$HEIGHT); }

$my_graph->set(

    x_labels_vertical => 1,
    y_max_value     => $max,
    y_tick_number   => 10,
    long_ticks      => 1,
    y_label_skip    => 2,
    x_label_skip    => $xskip,
    x_all_ticks     => 1,
    bar_spacing     => 4,
    shadow_depth    => 3,
    fgclr           => 'gold',
    bgclr           => 'black',
    boxclr          => 'white',
    accentclr       => 'lorange',
    shadowclr       => 'dblue',
    labelclr        => 'gold',
    axislabelclr        => 'gold',
    legendclr        => 'white',
    textclr         => 'cyan',
    dclrs           =>  [ qw(marine cyan) ],
    transparent     => 0,
    t_margin        => 10,
    b_margin        => 10,
    l_margin        => 10,
    r_margin        => 10,
    show_values     => $SHOW_VALUES,

)
or warn $my_graph->error;

binmode STDOUT;
print header('image/png');
print $my_graph->plot($data)->png;

#
# END
#


-- 
Joe
http://www.joekaz.net/
http://www.cafeshops.com/joekaz
Received on Thu Apr 15 2004 - 07:03:44 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US