/
misc06.php
132 lines (111 loc) · 4.39 KB
/
misc06.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Usage example for Image_Graph.
*
* Main purpose:
* "Semi-real" plot
*
* Other:
* Gradient filling, Icon markers (and marker array), Datapreprocessor
*
* $Id: misc06.php,v 1.4 2005/08/03 21:21:53 nosey Exp $
*
* @package Image_Graph
* @author Jesper Veggerby <pear.nosey@veggerby.dk>
*/
require_once 'Image/Graph.php';
// create the graph
$Graph =& Image_Graph::factory('graph', array(400, 300));
// add a TrueType font
$Arial =& $Graph->addNew('font', 'Verdana');
// set the font size to 8 pixels
$Arial->setSize(8);
// set default font color to white
$Arial->setColor('white');
// make the entire graph use this font
$Graph->setFont($Arial);
// create the graph layout
$Graph->add(
Image_Graph::vertical(
Image_Graph::factory('title', array('German Car Popularity', 11)),
Image_Graph::vertical(
$Plotarea = Image_Graph::factory('plotarea'),
$Legend = Image_Graph::factory('legend'),
90
),
7
)
);
// associate the legend with the plotarea
$Legend->setPlotarea($Plotarea);
// make the graph have a gradient filled background
$Graph->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'green', 'lightblue')));
// and a black border
$Graph->setBorderColor('black');
// create and populate the dataset for 'popularity'
$Dataset =& Image_Graph::factory('dataset');
$Dataset->addPoint('Audi', 100);
$Dataset->addPoint('Mercedes', 41);
$Dataset->addPoint('Porsche', 78);
$Dataset->addPoint('BMW', 12);
// create and populate the dataset for 'defects / 1000 units'
$Dataset2 =& Image_Graph::factory('dataset');
$Dataset2->addPoint('Audi', 10);
$Dataset2->addPoint('Mercedes', 17);
$Dataset2->addPoint('Porsche', 12);
$Dataset2->addPoint('BMW', 21);
// add a line grid
$GridY =& $Plotarea->addNew('line_grid', null, IMAGE_GRAPH_AXIS_Y);
// make it have a slightly transparent white color
$GridY->setLineColor('white@0.8');
// create the plot as bar chart using the 'popularity' dataset
$Plot =& $Plotarea->addNew('bar', array(&$Dataset));
// set the plot title (for legends)
$Plot->setTitle('Popularity');
// create a fill array to make the bars have individual fill's
$FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'orange'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'blue'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'yellow'));
$FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'red'));
// make the 'popularity' plot use this fillarray
$Plot->setFillStyle($FillArray);
// create a marker array and populate it with icon markers
$Marker =& $Graph->addNew('Image_Graph_Marker_Array');
$Marker->addNew('icon_marker', './images/audi.png');
$Marker->addNew('icon_marker', './images/mercedes.png');
$Marker->addNew('icon_marker', './images/porsche.png');
$Marker->addNew('icon_marker', './images/bmw.png');
// make the plot use the marker array
$Plot->setMarker($Marker);
// create the 2nd plot ('defects / 1000 units') as a line plot and associate
// it with the secondary y-axis (implicitly this creates a y-axis of the class
// Image_Graph_Axis)
$Plot2 =& $Plotarea->addNew('line', array(&$Dataset2), IMAGE_GRAPH_AXIS_Y_SECONDARY);
// set the plot title
$Plot2->setTitle('Defects');
// and line style
$Plot2->setLineColor('gray@0.8');
// create a value marker to display the actual y-values
$Marker =& $Graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
// and make the line plot use this
$Plot2->setMarker($Marker);
// make the marker print using font-size 7
$Marker->setFontSize(7);
// ... in blue
$Marker->setFontColor('blue');
// get the y-axis
$AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
// and create a datapreprocessor to make the labels print out as percentage valuexs
$AxisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.0f%%'));
// force a maximum on the y-axis to 105
$AxisY->forceMaximum(105);
// set the axis title and make it display vertically ('vertical' = down->up)
$AxisY->setTitle('Popularity', 'vertical');
// get the secondary y-axis
$AxisYsec =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y_SECONDARY);
// set the axis title and make it display vertically ('vertical2' = up->down)
$AxisYsec->setTitle('Defects / 1000 units', 'vertical2');
// output the Graph
$Graph->done();
?>