Grafiek class
Ik heb een grafiek class die ik wil gebruiken maar hij geeft een foutmelding van headers already sent op regel 380.
Ik heb al van alles geprobeert zoals ob_start(); enz maar het lukt me niet om de foutmelding weg te krijgen.
Ik heb al van alles geprobeert zoals ob_start(); enz maar het lukt me niet om de foutmelding weg te krijgen.
Code (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?php
class Graph{
// Standaard config. Valt te veranderen via variabelen en functies hier onder!
var $height = 300;
var $width = 600;
// Ruimte aan de zijkant.
// Ook instelbaar met SetMargins(links, boven, rechts, onder)
var $border_left = 50;
var $border_top = 10;
var $border_bottom = 50;
var $border_right = 10;
// Punt grootte. Zet op 0 om uit te schakelen.
var $dotSize = 4;
// Standaard teksten die beide assen identificeren
var $tags = array('X','Y');
// Font instellingen
var $Font = "arial.ttf";
var $FontSize = 12;
var $FontSizeNumbers = 8;
// Hier staan de standaard kleuren gedefineerd.
// Er achter staat aangegeven welk type het is bij de functie SetColor, en welke kleur het in de grafiek is.
var $ColorBorder = array(200, 100, 33); // border (rand om de grafiek heen)
var $ColorFont = array(100, 100, 100); // font (letters kleur)
var $ColorGraphLine = array(0, 150, 0); // line (grafiek lijn)
var $ColorGrid = array(230, 230, 230); // grid (raster kleur)
var $ColorInBackground = array(255, 255, 255); // gridbackground (achtergrond kleur van de grafiek)
var $ColorOutBackground = array(230, 230, 230); // background (achtergrond kleur van de buiten rand)
// Gegevens opslag
var $data = array();
// Verander een kleur
// Welk type je moet invoeren is hier boven te vinden bij de kleuren definitie's.
// Je kan zowel een hex code invoer geven (dus #FF00FF), of een array met RGB kleuren. Bijvoorbeeld array(255,0,255).
function SetColor($type, $color)
{
if (is_array($color))
{
$c = $color;
}
else
{
if (substr($color,0,1) == "#")
{
// HEX
$code = substr($color,1);
$codeR = substr($code,0,2);
$codeG = substr($code,2,2);
$codeB = substr($code,4,2);
$c = array(hexdec($codeR),hexdec($codeB),hexdec($codeG));
}
else
$this->displayError('Voer enkel invoer is als HEX string (met #) of array(R,G,B) (RGB kleuren)');
}
switch (strtolower($type))
{
case 'border':
$this->ColorBorder = $c;
break;
case 'grid':
$this->ColorGrid = $c;
break;
case 'font':
$this->ColorFont = $c;
break;
case 'line':
$this->ColorGraphLine = $c;
break;
case 'background':
$this->ColorOutBackground = $c;
break;
case 'gridbackground':
$this->ColorInBackground = $c;
break;
default:
$this->displayError($type . ' is geen geldige kleur type');
break;
}
}
// Met deze functie stel je de gegevens voor de grafiek in.
function setData($data) {
$this->data = $data;
} // end function
// Met deze functie zet je de tekstjes aan de zijkant vast
function setTags($left, $bottom) {
$this->tags = array($left, $bottom);
} // end function
// Verander het font en de grootte
// Font: Een TrueType font, of wel TTF. Kopieer bijvoorbeeld uit /WINDOWS/Fonts/
// Text_size: Specificeer in pixels hoe groot de text moet worden geschreven.
// Number_size: Specificeer in pixels hoe groot de getallen moet worden geschreven.
function SetFont($font, $text_size, $number_size)
{
$this->Font = $font;
$this->FontSize = $text_size;
$this->FontSizeNumbers = $number_size;
}
// Verander de lege vlaktes aan de zijkanten e.d.
function SetMargins($left, $top, $right, $bottom)
{
$this->border_left = $left;
$this->border_top = $top;
$this->border_right = $right;
$this->border_bottom = $bottom;
}
// Verander de grafiek grootte
function SetDimensions($width=-1, $height=-1)
{
if ($width>1)
$this->width = $width;
if ($height>1)
$this->height = $height;
}
// Teken de grafiek
// Door als 1ste argument true op te geven kan je het plaatjes object bemachtigen
// Voor normaal gebruik gewoon render() toepassen.
function render($return =false) {
// Instellingen inladen
$height = $this->height;
$width = $this->width;
$border_left = $this->border_left;
$border_top = $this->border_top;
$border_bottom = $this->border_bottom;
$border_right = $this->border_right;
$dotSize = $this->dotSize;
// Creer het plaatje
$im = imagecreate($width, $height);
// Kleur inladen.
$back = imagecolorallocate($im, $this->ColorInBackground[0], $this->ColorInBackground[1], $this->ColorInBackground[2]);
$border = imagecolorallocate($im, $this->ColorOutBackground[0], $this->ColorOutBackground[1], $this->ColorOutBackground[2]);
$raster = imagecolorallocate($im, $this->ColorGrid[0], $this->ColorGrid[1], $this->ColorGrid[2]);
$txt = imagecolorallocate($im, $this->ColorFont[0], $this->ColorFont[1], $this->ColorFont[2]);
$gline = imagecolorallocate($im, $this->ColorGraphLine[0], $this->ColorGraphLine[1], $this->ColorGraphLine[2]);
$line = imagecolorallocate($im, $this->ColorBorder[0], $this->ColorBorder[1], $this->ColorBorder[2]);
// We vullen de zijkanten op met de kleuren.
// Links
imagefilledpolygon($im,
array(
0,0,
0,$height,
$border_left,$height,
$border_left,0
),
4,
$border
);
// Boven
imagefilledpolygon($im,
array(
0,0,
0,$border_top,
$width,$border_top,
$width,0
),
4,
$border
);
// Onder
imagefilledpolygon($im,
array(
0, ($height - $border_bottom),
0, $height,
$width, $height,
$width, ($height - $border_bottom)
),
4,
$border
);
// Rechts
imagefilledpolygon($im,
array(
($width - $border_right), 0,
($width - $border_right), $height,
$width, $height,
$width, 0
),
4,
$border
);
// Scheidings lijn tussen de buitenkant en de grafiek
imageline($im, $border_left, $border_top, $border_left, ($height - $border_bottom), $line); // left
imageline($im, $border_left, $border_top, ($width - $border_right-1), $border_top, $line); // top
imageline($im, $border_left, ($height-$border_bottom), ($width - $border_right-1), ($height - $border_bottom), $line); // bottom
imageline($im, ($width - $border_right-1), ($height - $border_bottom), ($width - $border_right-1), $border_top, $line); // right
// Het analyseren van de gegevens!
$ruimte_grafiek_width = ($width - $border_left - $border_right);
$ruimte_grafiek_height = ($height - $border_top - $border_bottom);
$gegevens = count($this->data)-1;
if ($gegevens < 2) {
$this->displayError("Need at least 3 records to make a graph, " . ($gegevens+1) . " given.");
return;
} // end if
$breedtePerGegeven = $ruimte_grafiek_width / $gegevens;
$hoogtePerEenheid = $ruimte_grafiek_height / 10;
$perKeerErbij = (max($this->data) - min($this->data)) / 10;
$getal = max($this->data);
$beginX = $border_left;
$beginY = $border_top;
// Deze functie tekent het raster, tekent de y as verdeling.
for ($i = 0; $i < 10; $i++) {
// raster lijn
if ($i != 0)
imageline($im, $border_left+1, $beginY, ($width - $border_right - 2), $beginY, $raster);
imageline($im, $border_left, $beginY, ($border_left+5), $beginY, $line);
$info = imagettfbbox($this->FontSizeNumbers, 0, $this->Font, round($getal, 1));
imagettftext($im, $this->FontSizeNumbers, 0, ($border_left - abs($info[4]) - 5), $beginY + 5, $txt, $this->Font, round($getal, 1));
$getal -= $perKeerErbij;
$beginY += $hoogtePerEenheid;
} // end if
$info = imagettfbbox($this->FontSizeNumbers, 0, $this->Font, floor($getal));
imagettftext($im, $this->FontSizeNumbers, 0, ($border_left - abs($info[4]) - 5), $beginY + 5, $txt, $this->Font, floor($getal));
// Als er een nullijn nodig is, moeten we die even tekenen.
if (min($this->data) < 0 && max($this->data) > 0) {
$nullijn_perc = 1 - abs(min($this->data)) / (abs(min($this->data)) + max($this->data));
$nullijn_pix = $nullijn_perc * $ruimte_grafiek_height + $border_top;
imageline($im, $border_left, $nullijn_pix, ($width - $border_right-1), $nullijn_pix, $line); // bottom
$info = imagettfbbox($this->FontSizeNumbers, 0, $this->Font, 0);
imagettftext($im, $this->FontSizeNumbers, 0, ($border_left + $ruimte_grafiek_width + abs($info[4])), $nullijn_pix + 5, $txt, $this->Font, 0);
} // end if
$i = 0;
// Teken het raster, en zet de verdeling van de x-as op z'n plek.
foreach ($this->data AS $naam => $value) {
$i++;
// raster lijn
if ($i != $gegevens+1 && $i != 1)
imageline($im, $beginX, $border_top, $beginX, ($height - $border_bottom), $raster);
$info = imagettfbbox($this->FontSizeNumbers, 90, $this->Font, $naam);
$heightSelf = abs($info[3]);
imageline($im, $beginX, ($height - $border_bottom), $beginX, ($height - $border_bottom - 5), $line);
imagettftext($im, $this->FontSizeNumbers, 90, $beginX+5, ($height - $border_bottom + $heightSelf + 10), $txt, $this->Font, $naam);
$beginX += $breedtePerGegeven;
} // end if
$beginX = $border_left;
$i = 0;
/// Teken de echte grafiek
foreach ($this->data AS $naam => $value) {
$i++;
if (max($this->data) == min($this->data))
$beginY = .5 * $ruimte_grafiek_height + $border_top;
else
$beginY = (1 - ($value - min($this->data)) / (max($this->data) - min($this->data))) * $ruimte_grafiek_height + $border_top;
if ($i != 1) {
// streep
imageline($im, $vorigeX, $vorigeY, $beginX, $beginY, $gline);
} // end if
$vorigeX = $beginX;
$vorigeY = $beginY;
$beginX += $breedtePerGegeven;
} // end foreach
$beginX = $border_left;
$i = 0;
// Teken eventueel nog de puntjes
if ($dotSize > 0)
{
foreach ($this->data AS $naam => $value) {
$i++;
if (max($this->data) == min($this->data))
$beginY = .5 * $ruimte_grafiek_height + $border_top;
else
$beginY = (1 - ($value - min($this->data)) / (max($this->data) - min($this->data))) * $ruimte_grafiek_height + $border_top;
// dot
imagefilledpolygon($im,
array(
($beginX - $dotSize), $beginY,
$beginX , ($beginY - $dotSize),
($beginX + $dotSize), $beginY,
$beginX , ($beginY + $dotSize)
),
4,
$line
);
$beginX += $breedtePerGegeven;
} // end foreach
}
// Schrijf de x en y as namen langs de zijkant.
# Onderin
$widthTxt = imagettfbbox($this->FontSize, 0, $this->Font, $this->tags[1]);
$widthTxt = $widthTxt[2];
imagettftext($im, $this->FontSize, 0, (($width-$widthTxt) / 2), ($height - 5), $txt, $this->Font, $this->tags[1]);
# Links
$heightTxt = imagettfbbox($this->FontSize, 90, $this->Font, $this->tags[0]);
$heightTxt = $heightTxt[3];
imagettftext($im, $this->FontSize, 90, 15, (($height-$heightTxt) / 2), $txt, $this->Font, $this->tags[0]);
// Ontsnap route om het image object te krijgen.
if ($return == true)
return $im;
header("Content-type: Image/PNG");
imagePng($im);
imageDestroy($im);
} // end function
// Indien er zich een foutmelding voordoet:
function displayError($fout) {
$im = imagecreate(500, 300);
imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 2, 10, 10, $fout, $black);
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
} // end function
} // end class
?>
class Graph{
// Standaard config. Valt te veranderen via variabelen en functies hier onder!
var $height = 300;
var $width = 600;
// Ruimte aan de zijkant.
// Ook instelbaar met SetMargins(links, boven, rechts, onder)
var $border_left = 50;
var $border_top = 10;
var $border_bottom = 50;
var $border_right = 10;
// Punt grootte. Zet op 0 om uit te schakelen.
var $dotSize = 4;
// Standaard teksten die beide assen identificeren
var $tags = array('X','Y');
// Font instellingen
var $Font = "arial.ttf";
var $FontSize = 12;
var $FontSizeNumbers = 8;
// Hier staan de standaard kleuren gedefineerd.
// Er achter staat aangegeven welk type het is bij de functie SetColor, en welke kleur het in de grafiek is.
var $ColorBorder = array(200, 100, 33); // border (rand om de grafiek heen)
var $ColorFont = array(100, 100, 100); // font (letters kleur)
var $ColorGraphLine = array(0, 150, 0); // line (grafiek lijn)
var $ColorGrid = array(230, 230, 230); // grid (raster kleur)
var $ColorInBackground = array(255, 255, 255); // gridbackground (achtergrond kleur van de grafiek)
var $ColorOutBackground = array(230, 230, 230); // background (achtergrond kleur van de buiten rand)
// Gegevens opslag
var $data = array();
// Verander een kleur
// Welk type je moet invoeren is hier boven te vinden bij de kleuren definitie's.
// Je kan zowel een hex code invoer geven (dus #FF00FF), of een array met RGB kleuren. Bijvoorbeeld array(255,0,255).
function SetColor($type, $color)
{
if (is_array($color))
{
$c = $color;
}
else
{
if (substr($color,0,1) == "#")
{
// HEX
$code = substr($color,1);
$codeR = substr($code,0,2);
$codeG = substr($code,2,2);
$codeB = substr($code,4,2);
$c = array(hexdec($codeR),hexdec($codeB),hexdec($codeG));
}
else
$this->displayError('Voer enkel invoer is als HEX string (met #) of array(R,G,B) (RGB kleuren)');
}
switch (strtolower($type))
{
case 'border':
$this->ColorBorder = $c;
break;
case 'grid':
$this->ColorGrid = $c;
break;
case 'font':
$this->ColorFont = $c;
break;
case 'line':
$this->ColorGraphLine = $c;
break;
case 'background':
$this->ColorOutBackground = $c;
break;
case 'gridbackground':
$this->ColorInBackground = $c;
break;
default:
$this->displayError($type . ' is geen geldige kleur type');
break;
}
}
// Met deze functie stel je de gegevens voor de grafiek in.
function setData($data) {
$this->data = $data;
} // end function
// Met deze functie zet je de tekstjes aan de zijkant vast
function setTags($left, $bottom) {
$this->tags = array($left, $bottom);
} // end function
// Verander het font en de grootte
// Font: Een TrueType font, of wel TTF. Kopieer bijvoorbeeld uit /WINDOWS/Fonts/
// Text_size: Specificeer in pixels hoe groot de text moet worden geschreven.
// Number_size: Specificeer in pixels hoe groot de getallen moet worden geschreven.
function SetFont($font, $text_size, $number_size)
{
$this->Font = $font;
$this->FontSize = $text_size;
$this->FontSizeNumbers = $number_size;
}
// Verander de lege vlaktes aan de zijkanten e.d.
function SetMargins($left, $top, $right, $bottom)
{
$this->border_left = $left;
$this->border_top = $top;
$this->border_right = $right;
$this->border_bottom = $bottom;
}
// Verander de grafiek grootte
function SetDimensions($width=-1, $height=-1)
{
if ($width>1)
$this->width = $width;
if ($height>1)
$this->height = $height;
}
// Teken de grafiek
// Door als 1ste argument true op te geven kan je het plaatjes object bemachtigen
// Voor normaal gebruik gewoon render() toepassen.
function render($return =false) {
// Instellingen inladen
$height = $this->height;
$width = $this->width;
$border_left = $this->border_left;
$border_top = $this->border_top;
$border_bottom = $this->border_bottom;
$border_right = $this->border_right;
$dotSize = $this->dotSize;
// Creer het plaatje
$im = imagecreate($width, $height);
// Kleur inladen.
$back = imagecolorallocate($im, $this->ColorInBackground[0], $this->ColorInBackground[1], $this->ColorInBackground[2]);
$border = imagecolorallocate($im, $this->ColorOutBackground[0], $this->ColorOutBackground[1], $this->ColorOutBackground[2]);
$raster = imagecolorallocate($im, $this->ColorGrid[0], $this->ColorGrid[1], $this->ColorGrid[2]);
$txt = imagecolorallocate($im, $this->ColorFont[0], $this->ColorFont[1], $this->ColorFont[2]);
$gline = imagecolorallocate($im, $this->ColorGraphLine[0], $this->ColorGraphLine[1], $this->ColorGraphLine[2]);
$line = imagecolorallocate($im, $this->ColorBorder[0], $this->ColorBorder[1], $this->ColorBorder[2]);
// We vullen de zijkanten op met de kleuren.
// Links
imagefilledpolygon($im,
array(
0,0,
0,$height,
$border_left,$height,
$border_left,0
),
4,
$border
);
// Boven
imagefilledpolygon($im,
array(
0,0,
0,$border_top,
$width,$border_top,
$width,0
),
4,
$border
);
// Onder
imagefilledpolygon($im,
array(
0, ($height - $border_bottom),
0, $height,
$width, $height,
$width, ($height - $border_bottom)
),
4,
$border
);
// Rechts
imagefilledpolygon($im,
array(
($width - $border_right), 0,
($width - $border_right), $height,
$width, $height,
$width, 0
),
4,
$border
);
// Scheidings lijn tussen de buitenkant en de grafiek
imageline($im, $border_left, $border_top, $border_left, ($height - $border_bottom), $line); // left
imageline($im, $border_left, $border_top, ($width - $border_right-1), $border_top, $line); // top
imageline($im, $border_left, ($height-$border_bottom), ($width - $border_right-1), ($height - $border_bottom), $line); // bottom
imageline($im, ($width - $border_right-1), ($height - $border_bottom), ($width - $border_right-1), $border_top, $line); // right
// Het analyseren van de gegevens!
$ruimte_grafiek_width = ($width - $border_left - $border_right);
$ruimte_grafiek_height = ($height - $border_top - $border_bottom);
$gegevens = count($this->data)-1;
if ($gegevens < 2) {
$this->displayError("Need at least 3 records to make a graph, " . ($gegevens+1) . " given.");
return;
} // end if
$breedtePerGegeven = $ruimte_grafiek_width / $gegevens;
$hoogtePerEenheid = $ruimte_grafiek_height / 10;
$perKeerErbij = (max($this->data) - min($this->data)) / 10;
$getal = max($this->data);
$beginX = $border_left;
$beginY = $border_top;
// Deze functie tekent het raster, tekent de y as verdeling.
for ($i = 0; $i < 10; $i++) {
// raster lijn
if ($i != 0)
imageline($im, $border_left+1, $beginY, ($width - $border_right - 2), $beginY, $raster);
imageline($im, $border_left, $beginY, ($border_left+5), $beginY, $line);
$info = imagettfbbox($this->FontSizeNumbers, 0, $this->Font, round($getal, 1));
imagettftext($im, $this->FontSizeNumbers, 0, ($border_left - abs($info[4]) - 5), $beginY + 5, $txt, $this->Font, round($getal, 1));
$getal -= $perKeerErbij;
$beginY += $hoogtePerEenheid;
} // end if
$info = imagettfbbox($this->FontSizeNumbers, 0, $this->Font, floor($getal));
imagettftext($im, $this->FontSizeNumbers, 0, ($border_left - abs($info[4]) - 5), $beginY + 5, $txt, $this->Font, floor($getal));
// Als er een nullijn nodig is, moeten we die even tekenen.
if (min($this->data) < 0 && max($this->data) > 0) {
$nullijn_perc = 1 - abs(min($this->data)) / (abs(min($this->data)) + max($this->data));
$nullijn_pix = $nullijn_perc * $ruimte_grafiek_height + $border_top;
imageline($im, $border_left, $nullijn_pix, ($width - $border_right-1), $nullijn_pix, $line); // bottom
$info = imagettfbbox($this->FontSizeNumbers, 0, $this->Font, 0);
imagettftext($im, $this->FontSizeNumbers, 0, ($border_left + $ruimte_grafiek_width + abs($info[4])), $nullijn_pix + 5, $txt, $this->Font, 0);
} // end if
$i = 0;
// Teken het raster, en zet de verdeling van de x-as op z'n plek.
foreach ($this->data AS $naam => $value) {
$i++;
// raster lijn
if ($i != $gegevens+1 && $i != 1)
imageline($im, $beginX, $border_top, $beginX, ($height - $border_bottom), $raster);
$info = imagettfbbox($this->FontSizeNumbers, 90, $this->Font, $naam);
$heightSelf = abs($info[3]);
imageline($im, $beginX, ($height - $border_bottom), $beginX, ($height - $border_bottom - 5), $line);
imagettftext($im, $this->FontSizeNumbers, 90, $beginX+5, ($height - $border_bottom + $heightSelf + 10), $txt, $this->Font, $naam);
$beginX += $breedtePerGegeven;
} // end if
$beginX = $border_left;
$i = 0;
/// Teken de echte grafiek
foreach ($this->data AS $naam => $value) {
$i++;
if (max($this->data) == min($this->data))
$beginY = .5 * $ruimte_grafiek_height + $border_top;
else
$beginY = (1 - ($value - min($this->data)) / (max($this->data) - min($this->data))) * $ruimte_grafiek_height + $border_top;
if ($i != 1) {
// streep
imageline($im, $vorigeX, $vorigeY, $beginX, $beginY, $gline);
} // end if
$vorigeX = $beginX;
$vorigeY = $beginY;
$beginX += $breedtePerGegeven;
} // end foreach
$beginX = $border_left;
$i = 0;
// Teken eventueel nog de puntjes
if ($dotSize > 0)
{
foreach ($this->data AS $naam => $value) {
$i++;
if (max($this->data) == min($this->data))
$beginY = .5 * $ruimte_grafiek_height + $border_top;
else
$beginY = (1 - ($value - min($this->data)) / (max($this->data) - min($this->data))) * $ruimte_grafiek_height + $border_top;
// dot
imagefilledpolygon($im,
array(
($beginX - $dotSize), $beginY,
$beginX , ($beginY - $dotSize),
($beginX + $dotSize), $beginY,
$beginX , ($beginY + $dotSize)
),
4,
$line
);
$beginX += $breedtePerGegeven;
} // end foreach
}
// Schrijf de x en y as namen langs de zijkant.
# Onderin
$widthTxt = imagettfbbox($this->FontSize, 0, $this->Font, $this->tags[1]);
$widthTxt = $widthTxt[2];
imagettftext($im, $this->FontSize, 0, (($width-$widthTxt) / 2), ($height - 5), $txt, $this->Font, $this->tags[1]);
# Links
$heightTxt = imagettfbbox($this->FontSize, 90, $this->Font, $this->tags[0]);
$heightTxt = $heightTxt[3];
imagettftext($im, $this->FontSize, 90, 15, (($height-$heightTxt) / 2), $txt, $this->Font, $this->tags[0]);
// Ontsnap route om het image object te krijgen.
if ($return == true)
return $im;
header("Content-type: Image/PNG");
imagePng($im);
imageDestroy($im);
} // end function
// Indien er zich een foutmelding voordoet:
function displayError($fout) {
$im = imagecreate(500, 300);
imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 2, 10, 10, $fout, $black);
header("Content-type: image/gif");
imagegif($im);
imagedestroy($im);
} // end function
} // end class
?>
Gesponsorde koppelingen:
Heb je alles al geprobeerd wat in het Faq #2 staat? Spaties voor <?php, BOM-stukje in je bestand, echo's in bestandjes waar je dit bestand in include?
Stom maar ik heb de spatie achte ?> weggehaald en nu doet het script het goed.



