Hi,

Some GD docs GD.pm or the GD::Graph FAQ or the GD::Graph::Map site

I have whacked a simple piece of code together for this type of thing. I am outputting the GD stuff to a PNG file and then displaying this in a web page.

This script is purely a sample it displays GD::Graph as well as GD::Graph::Map which allows you to click on the bar and output a further query that is run in from the @urls script not show here.

#!perl.exe use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use GD; use GD::Graph; use GD::Graph::bars; use GD::Graph::Map; use DBI; use DBD::ODBC; my $query = new CGI; print $query->header; print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"10\">"; print $query->start_html( -title =>'Number Of Calls', -BGCOLOR=>"#A8A8DO"); # Print the first form print $query->startform; print "<center>\n"; print "<H1>Total Calls Graph v1.0.1</H1>\n"; print "<p><br></p><p>\n"; my @mds = (); my @tmp_mds = ("ServerA","ServerB","ServerC","ServerD"); my @vals = (); my $tot_call = 0; my @urls = ["../cgi-bin/CallWeb.pl?Md=ServerA", "../cgi-bin/CallWeb.pl?Md=ServerB", "../cgi-bin/CallWeb.pl?Md=ServerC", "../cgi-bin/CallWeb.pl?Md=ServerD", ]; my $dbh = DBI->connect("dbi:ODBC:driver={SQL Server};server=DBServer;d +atabase=Calls;uid=sa;pwd=password;") or die "Cannot connect to DB :$! +\n"; foreach my $md ( @tmp_mds ) { my $sql_query = "SELECT COUNT(MD) from OpenCalls where MD like '%$ +md%'"; my $sth = $dbh->prepare($sql_query) or die "Problems Preparing the + SQL Statement\n"; $sth->execute() or die "Problems Executing the SQL Statement\n"; my $num = $sth->fetchrow; push (@vals, $num); } foreach my $call (@vals) { $tot_call = $tot_call + $call; } $mds[0] = [@tmp_mds]; $mds[1] = [@vals]; my $graph = GD::Graph::bars->new(800, 500); my $maxval = $vals[ my $index = 0 ] if @vals; for (0 .. $#vals) { if ($maxval < $vals[$_]) { $index = $_; $maxval = $vals[$_]; } } $maxval = ($maxval + 10); $graph->set( x_label => 'Servers', x_label_position => '.5', y_label => 'Number of Calls', title => "Auto Calls PER Server - Total Calls = $tot_call", y_max_value => $maxval, y_tick_number => ($maxval/5), y_label_skip => 2, #Set the bar colours to Green dclrs => [ qw(green) ], # Draw bars with width 3 pixels bar_width => 3, # Sepearte the bars with 4 pixels bar_spacing => 10, # Show values on top of each bar show_values => 1, #Add a drop shadow shadow_depth => 4, shadowclr => 'dgreen', ); open PNG, ">../htdocs/pics/call_graph.png"; binmode PNG; print PNG $graph->plot(\@mds)->png; close PNG; my $map = new GD::Graph::Map($graph, hrefs =>\@urls , noImgMarkup =>1, img_TARGET => 'query', mapName =>"call_graph", info => 'No. of Calls for %x : %y' ); #finally, show the html print '<IMG BORDER = 0 SRC="../pics/call_graph.png" usemap="#call_grap +h">', ($map->imagemap("call_graph.png", \@mds)), "\n"; print "<P><B>Number of events in buffer : " . &Num_Event; print "</B></P></center><hr>\n";

>/readmore> I am doing several things here, some of which are bad but the concept should be right..? at the end of the day you should be able to see that I get the values for the BAR graph from a db.

Update: The Password and db stuff were only for demo purposes I would NEVER suggest you do this.

-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to Re: Creating and writing Graphs to File by AcidHawk
in thread Creating and writing Graphs to File by toddy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.