Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

CGI pie-graph Maker

by BigJoe (Curate)
on May 02, 2001 at 18:19 UTC ( #77327=sourcecode: print w/ replies, xml ) Need Help??

Category: CGI programming
Author/Contact Info Joseph Harnish
big_joe1008@yahoo.com
Description: This is very similar to the Bar graph maker. But this one will do a Pie chart. The same parameters apply.
  • cols are the names of the values
  • vals are the corrisponding values

title is optional on this.
#!/usr/bin/perl
#################################################################
#   Author      Joseph Harnish        big_joe1008@yahoo.com        #
#   Date        5/1/2001                                        #
#                                                                #
#   This script is a wrapper for GD::Graph::Bars for use on     #
#    web pages.  It is a quicky that is used inside of an         #
#   IFRAME.                                                           
+           #
#                                                                #
#   Usage:  piegraph.pl?cols=A,B,C&vals=1,2,3                    #
#   It is required to have a "cols" and a "vals" but there are  #
#   options you can also add.  These options are:                    #
+   
#     title                                                           
+   #    
#################################################################
use GD::Graph::pie;
use CGI;

my $q = new CGI;
my $cols = $q->param("cols");
my $title = $q->param("title");
my $vals = $q->param("vals");
my @col = split(/\,/, $cols);
my @val = split(/\,/, $vals);
my $temp;

# Test the values comming in.
foreach (@val) {
  $temp += $_;
}
if($temp != 100){
  print $q->header;
  print "<h1>Error:  The values must add up to 100</h1>Your total was 
+$temp<br>\n";
  exit;
}

if($#col != $#val){
    print $q->header;
    print "<b><h1>Error:  Parameters are not balanced</h1></b>";
    exit;
}
#create and display the graph
my $graph = new GD::Graph::pie(200,200);
my @data = ([@col], [@val]);
$graph->set(title => "$title") if($title ne '');
$graph->set_label_font('ARIAL.TTF', 24);
$graph->set_value_font('ARIAL.TTF', 24);
print $q->header("image/png");
binmode STDOUT;
print $graph->plot(\@data)->png;

Comment on CGI pie-graph Maker
Download Code
Re: CGI pie-graph Maker
by CountZero (Bishop) on Dec 08, 2002 at 20:08 UTC

    There is an interesting module called Apache::GD::Graph which can make bar charts, pie graphs, area charts, ... just by using a virtual location on the Apache-server and providing the data to be shown in the URL.

    Just search CPAN or use ppm.

    Still your program remains interesting, if you want to get down to making the graphs yourself.

    Count Zero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Back to Code Catacombs

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2014-07-25 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls