-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPHPChart.php
101 lines (68 loc) · 2.12 KB
/
PHPChart.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
<?php
#noe
class PHPChart extends PHPChart_Component {
const LEFT = 1;
const RIGHT = 2;
const TOP = 4;
const BOTTOM = 8;
const CENTER = 16;
private $backgroundcolor = '#ffffff00';
private $lines = array();
private $mainchart = null;
private $legend = null;
private $components = array();
private $driver;
private $format;
private $x1space;
private $y1space;
private $x2space;
private $y2space;
protected $margin = array(0,0,0,0);
function __construct($width, $height) {
$this->height = $height;
$this->width = $width;
}
function setDriver(PHPChart_Driver $driver) {
$this->driver = $driver;
$driver->init($this->width, $this->height, $this->backgroundcolor, $this->format);
}
function getDriver() {
return $this->driver;
}
function getParentComponent() {
return $this;
}
function getSpace() {
return array($this->x1space, $this->y1space, $this->x2space, $this->y2space);
}
function setSpace(array $array) {
list($this->x1space, $this->y1space, $this->x2space, $this->y2space) = $array;
}
function calculateDimensions() {
$this->ytop = $this->margin[0] + $this->padding[0];
$this->ybottom = $this->height - ($this->margin[0] + $this->padding[0] + $this->margin[2] + $this->padding[2]);
$this->xleft = $this->margin[3] + $this->padding[3];
$this->xright = $this->width - ($this->margin[3] + $this->padding[3] + $this->margin[1] + $this->padding[1]);
}
function render() {
//Set up some params
$this->calculateDimensions();
$this->x1space = $this->xleft;
$this->x2space = $this->xright;
$this->y1space = $this->ytop;
$this->y2space = $this->ybottom;
$this->drawBackground();
$this->legend->render();
$this->mainchart->render();
header("Content-type: image/png");
echo $this->driver->getimage();
}
function setChart(PHPChart_AbstractChart $graph) {
$this->mainchart = $graph;
$graph->setChart($this);
}
function setLegend(PHPChart_Legend $graph) {
$this->legend = $graph;
$graph->setChart($this);
}
}