1<?php
2/**
3 * Usage example for Image_Graph.
4 *
5 * Main purpose:
6 * Show stacked bar chart 100%
7 *
8 * Other:
9 * None specific
10 *
11 * $Id: plot_bar_stacked100pct.php 192339 2005-08-03 21:22:11Z nosey $
12 *
13 * @package Image_Graph
14 * @author Jesper Veggerby <pear.nosey@veggerby.dk>
15 */
16
17
18include_once('Image/Graph.php');
19include_once('Image/Graph/Marker/Value.php');
20
21class myValueMarker extends Image_Graph_Marker_Value {
22
23  function getDisplayValue($Values) {
24  	return "\{$Values[Y]}";
25  }
26
27}
28
29
30// create the graph
31$Graph =& Image_Graph::factory('graph', array(400, 300));
32// add a TrueType font
33$Font =& $Graph->addNew('font', 'Verdana');
34// set the font size to 11 pixels
35$Font->setSize(8);
36
37$Graph->setFont($Font);
38
39$Graph->add(
40    Image_Graph::vertical(
41        Image_Graph::factory('title', array('Stacked Bar 100% Chart Sample', 12)),
42        Image_Graph::vertical(
43            $Plotarea = Image_Graph::factory('plotarea'),
44            $Legend = Image_Graph::factory('legend'),
45            90
46        ),
47        5
48    )
49);
50$Legend->setPlotarea($Plotarea);
51
52for ($j = 0; $j<4; $j++) {
53	$DX =& Image_Graph::factory('dataset');
54	$Datasets[$j] =& $DX;
55	for ($i = 0; $i<10; $i++)
56		$DX->addPoint($i, rand(2, 15), $j);
57}
58
59// create the 1st plot as smoothed area chart using the 1st dataset
60$Plot =& $Plotarea->addNew('bar', array($Datasets, 'stacked100pct'));
61
62// set a line color
63$Plot->setLineColor('gray');
64
65// create a fill array
66$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
67$FillArray->addColor('blue@0.2');
68$FillArray->addColor('yellow@0.2');
69$FillArray->addColor('green@0.2');
70$FillArray->addColor('red@0.2');
71$FillArray->addColor('gray@0.2');
72
73// set a standard fill style
74$Plot->setFillStyle($FillArray);
75
76// create a Y data value marker
77$Marker =& $Plot->add(new myValueMarker(IMAGE_GRAPH_VALUE_Y));
78// and use the marker on the 1st plot
79$Plot->setMarker($Marker);
80
81// output the Graph
82$Graph->done();
83?>
84