#!/usr/bin/perl
#Include current script directory in the module path (needed on Microsoft IIS).
#This allows this script to work by copying ChartDirector to the same directory
#as the script (as an alternative to installation in Perl module directory)
use File::Basename;
use lib dirname($0);
use perlchartdir;
#
#For demo purpose, we use hard coded data. In real life, the following data
#could come from a database.
#
my $revenue = [4500, 5600, 6300, 8000, 12000, 14000, 16000, 20000, 24000, 28000]
;
my $labels = ["1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999",
"2000", "2001"];
#Create a XYChart object of size 450 x 200 pixels
my $c = new XYChart(450, 200);
#Add a title to the chart using Times Bold Italic font
$c->addTitle("Annual Revenue for Star Tech", "timesbi.ttf");
#Set the plotarea at (60, 25) and of size 350 x 150 pixels
$c->setPlotArea(60, 25, 350, 150);
#Add a blue (0x3333cc) bar chart layer using the given data. Set the bar border
#to 1 pixel 3D style.
$c->addBarLayer($revenue, 0x3333cc, "Revenue")->setBorderColor(-1, 1);
#Set x axis labels using the given labels
$c->xAxis()->setLabels($labels);
#Add a title to the y axis
$c->yAxis()->setTitle("USD (K)");
#Create the image and save it in a temporary location
my $chart1URL = $c->makeTmpFile("/tmp/tmpcharts");
#Create an image map for the chart
my $imageMap = $c->getHTMLImageMap("clickline.pl", "",
"title='{xLabel}: USD {value|0}K'");
print "Content-type: text/html\n\n";
print <
Simple Clickable Bar Chart
View Source Code
|