#!/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;
# The data for the bar chart
my $data0 = [100, 125, 156, 147, 87, 124, 178, 109, 140, 106, 192, 122];
my $data1 = [122, 156, 179, 211, 198, 177, 160, 220, 190, 188, 220, 270];
my $data2 = [167, 190, 213, 267, 250, 320, 212, 199, 245, 267, 240, 310];
my $labels = ["TJ", "AMK", "HZ", "TJ", "AMK", "HZ", "TJ", "AMK", "HZ", "TJ", "AMK", "HZ"];
# Create a XYChart object of size 540 x 375 pixels
my $c = new XYChart(540, 400);
# Add a title to the chart using 18 pts Times Bold Italic font
$c->addTitle("Average Weekly Network Load", "timesbi.ttf", 18);
# Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical
# gradient color from light blue (f9f9ff) to blue (6666ff) as background. Set border
# and grid lines to white (ffffff).
$c->setPlotArea(50, 55, 440, 280, $c->linearGradientColor(0, 55, 0, 335, 0xf9f9ff,
0x6666ff), -1, 0xffffff, 0xffffff);
# Add a legend box at (50, 28) using horizontal layout. Use 10pts Arial Bold as font,
# with transparent background.
$c->addLegend(50, 28, 0, "arialbd.ttf", 10)->setBackground($perlchartdir::Transparent
);
# Set the x axis labels
$c->xAxis()->setLabels($labels);
# Draw the ticks between label positions (instead of at label positions)
$c->xAxis()->setTickOffset(0.5);
#$c->xAxis()->setTickLength(50, 20);
# Set axis label style to 8pts Arial Bold
$c->xAxis()->setLabelStyle("arialbd.ttf", 8);
$c->yAxis()->setLabelStyle("arialbd.ttf", 8);
# Set axis line width to 2 pixels
$c->xAxis()->setWidth(2);
$c->yAxis()->setWidth(2);
# Add axis title
$c->yAxis()->setTitle("Throughput (MBytes Per Hour)");
# Add a multi-bar layer with 3 data sets
my $layer = $c->addBarLayer2($perlchartdir::Stack);
$layer->addDataSet($data0, 0xff0000, "Server #1");
$layer->addDataSet($data1, 0x00ff00, "Server #2");
$layer->addDataSet($data2, 0xff8800, "Server #3");
# Set bar border to transparent. Use glass lighting effect with light direction from
# left.
$layer->setBorderColor($perlchartdir::Transparent, perlchartdir::glassEffect(
$perlchartdir::NormalGlare, $perlchartdir::Left));
$c->layout();
my $labels2 = ["Jun", "Jun", "Jun", "Jun", "Jul", "Jul", "Aug", "Aug", "Aug", "Aug", "Aug", "Sep"];
my $labels3 = ["XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "QQQ", "QQQ", "QQQ", "QQQ", "QQQ", "QQQ"];
my @labelLayers = ($labels2, $labels3);
for (my $ii = 0; $ii <= $#labelLayers; ++$ii) {
$labels = $labelLayers[$ii];
my $lastXCoor = 0;
my $noOfLabels = scalar(@$labels);
for (my $i = 0; $i < $noOfLabels; ++$i) {
if (($i == $noOfLabels - 1) || ($$labels[$i] ne $$labels[$i + 1])) {
$c->addText($c->getXCoor(($lastXCoor + $i) / 2.0), 350 + (($ii + 0.5) * 25), $$labels[$i], "arialbi.ttf", 10, 0x000000, $perlchartdir::Center);
$lastXCoor = $i + 1;
if ($i != $noOfLabels - 1) {
$c->addLine($c->getXCoor($lastXCoor - 0.5), 335, $c->getXCoor($lastXCoor - 0.5), 350 + ($ii * 25) + 25, 0x000000);
}
}
}
}
$c->addLine(50, 335, 50, 350 + ($#labelLayers * 25) + 25, 0x000000);
$c->addLine(50 + 440, 335, 50 + 440, 350 + ($#labelLayers * 25) + 25, 0x000000);
# output the chart
binmode(STDOUT);
print "Content-type: image/png\\n\\n";
print $c->makeChart2($perlchartdir::PNG);
|