<?php
require_once("../lib/phpchartdir.php");
# The data for the bar chart
$data0 = array(44, 55, 100, 111);
$data1 = array(97, 87, 167, 222);
$data2 = array(156, 78, 147, 33);
$data3 = array(125, 0, 211, 235);
$data4 = array(44, 0, 100, 22);
$data5 = array(97, 0, 167, 7);
$data6 = array(156, 0, 0, 186);
$data7 = array(125, 118, 0, 0);
$data8 = array(44, 55, 0, 54);
# The labels for the bar chart. The labels contains embedded images as icons.
$labels = array("QQQQ", "WWWW", "RRRR", "TTTT");
# Create a XYChart object of size 600 x 350 pixels, using 0xe0e0ff as the background
# color, 0xccccff as the border color, with 1 pixel 3D border effect.
$c = new XYChart(600, 350, 0xe0e0ff, 0xccccff, 1);
#Set directory for loading images to current script directory
#Need when running under Microsoft IIS
$c->setSearchPath(dirname(__FILE__));
# Add a title to the chart using 14 points Times Bold Itatic font and light blue
# (0x9999ff) as the background color
$textBoxObj = $c->addTitle("Business Results 2001 vs 2002", "timesbi.ttf", 14);
$textBoxObj->setBackground(0x9999ff);
# Set the plotarea at (60, 45) and of size 500 x 210 pixels, using white (0xffffff)
# as the background
$c->setPlotArea(60, 45, 500, 210, 0xffffff);
# Swap the x and y axes to create a horizontal bar chart
$c->swapXY();
# Add a title to the y axis using 11 pt Times Bold Italic as font
$c->yAxis->setTitle("Revenue (millions)", "timesbi.ttf", 11);
# Set the labels on the x axis
$c->xAxis->setLabels($labels);
# Disable x-axis ticks by setting the tick length to 0
$c->xAxis->setTickLength(0);
# Add a stacked bar layer to the chart
for ($i = 0; $i < count($data0); ++$i)
{
$layer = $c->addBarLayer2(Stack);
$barCount = 0;
# Add the first two data sets to the chart as a stacked bar group
$layer->addDataGroup("2001");
if (($data0[$i] != 0) || ($data1[$i] != 0) || ($data2[$i] != 0))
{
$layer->addDataSet(array_reverse(array_pad(array($data0[$i]), $i + 1, NoValue)), 0xff6666, "AAA");
$layer->addDataSet(array_reverse(array_pad(array($data1[$i]), $i + 1, NoValue)), 0x6666ff, "BBB");
$layer->addDataSet(array_reverse(array_pad(array($data2[$i]), $i + 1, NoValue)), 0x66ff66, "CCC");
++$barCount;
}
# Add the remaining data sets to the chart as another stacked bar group
if (($data3[$i] != 0) || ($data4[$i] != 0) || ($data5[$i] != 0))
{
$layer->addDataGroup("2002");
$layer->addDataSet(array_reverse(array_pad(array($data3[$i]), $i + 1, NoValue)), 0xff6666, "DDD");
$layer->addDataSet(array_reverse(array_pad(array($data4[$i]), $i + 1, NoValue)), 0x6666ff, "EEE");
$layer->addDataSet(array_reverse(array_pad(array($data5[$i]), $i + 1, NoValue)), 0x66ff66, "FFF");
++$barCount;
}
if (($data6[$i] != 0) || ($data7[$i] != 0) || ($data8[$i] != 0))
{
$layer->addDataGroup("2003");
$layer->addDataSet(array_reverse(array_pad(array($data6[$i]), $i + 1, NoValue)), 0xff6666, "GGG");
$layer->addDataSet(array_reverse(array_pad(array($data7[$i]), $i + 1, NoValue)), 0x6666ff, "HHH");
$layer->addDataSet(array_reverse(array_pad(array($data8[$i]), $i + 1, NoValue)), 0x66ff66, "III");
++$barCount;
}
$layer->setBarGap(1 - (0.8 * $barCount / 3), TouchBar);
$layer->setAggregateLabelFormat("Year {dataGroupName}");
$layer->setAggregateLabelStyle("arialbi.ttf", 8);
$layer->setLegendOrder(NoLegend);
}
# Reverse 20% space at the right during auto-scaling to allow space for the aggregate
# bar labels
$c->yAxis->setAutoScale(0.2);
# Add a legend box at (310, 300) using TopCenter alignment, with 2 column grid
# layout, and use 8 pts Arial Bold Italic as font
$legendBox = $c->addLegend2(310, 300, false, "arialbi.ttf", 8);
$legendBox->setAlignment(TopCenter);
$legendBox->addKey("AAA", 0xff6666);
$legendBox->addKey("BBB", 0x6666ff);
$legendBox->addKey("CCC", 0x66ff66);
# Set the format of the text displayed in the legend box
$legendBox->setText("Year {dataGroupName} {dataSetName} Revenue");
# Set the background and border of the legend box to transparent
$legendBox->setBackground(Transparent, Transparent);
# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>
|