grafiek
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
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
<?php
$all_prices = "100,150,175,100,200,210,200,150,155,164,143,154";
$naam = "Grafiek";
$prices = explode(",",$all_prices);
sort($prices);
$count = count($prices) - 1;
$laagste = $prices[0];
$hoogste = $prices[$count];
$verschil = $hoogste - $laagste;
if ($verschil < 16){
$stap = 1;
}else{
$stap = $verschil / 16;
}
$prices = explode(",",$all_prices);
header("Content-type: image/png");
$im = imagecreatetruecolor (500, 400);
$wit = imagecolorallocate($im, 255, 255, 255);
$zwart = imagecolorallocate($im, 0, 0, 0);
$grijs = imagecolorallocate($im, 70, 70, 70);
$groen = imagecolorallocate($im, 0, 255, 0);
#verticaal
if ($verschil < 16){
$new_hoogste = 16 + $laagste;
}else{
$new_hoogste = $hoogste;
}
imagestring($im, 3, 10, 20, $new_hoogste, $wit);
imagestring($im, 3, 10, 40, round(15 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 60, round(14 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 80, round(13 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 100, round(12 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 120, round(11 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 140, round(10 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 160, round(9 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 180, round(8 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 200, round(7 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 220, round(6 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 240, round(5 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 260, round(4 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 280, round(3 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 300, round(2 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 320, round(1 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 340, $laagste, $wit);
imageline($im, 50, 27 , 500, 27 , $grijs);
imageline($im, 50, 47 , 500, 47 , $grijs);
imageline($im, 50, 67 , 500, 67 , $grijs);
imageline($im, 50, 87 , 500, 87 , $grijs);
imageline($im, 50, 107, 500, 107, $grijs);
imageline($im, 50, 127, 500, 127, $grijs);
imageline($im, 50, 147, 500, 147, $grijs);
imageline($im, 50, 167, 500, 167, $grijs);
imageline($im, 50, 187, 500, 187, $grijs);
imageline($im, 50, 207, 500, 207, $grijs);
imageline($im, 50, 227, 500, 227, $grijs);
imageline($im, 50, 247, 500, 247, $grijs);
imageline($im, 50, 267, 500, 267, $grijs);
imageline($im, 50, 287, 500, 287, $grijs);
imageline($im, 50, 307, 500, 307, $grijs);
imageline($im, 50, 327, 500, 327, $grijs);
imageline($im, 50, 347, 500, 347, $grijs);
#horizontaal - datum
for($i = 0; $i <= 22; $i++){
$x1 = 70 + 20 * $i;
$x2 = 45 + 20 * $i;
if (19 + $i > 30){
$datum = $i - 11;
}else{
$datum = 20 + $i;
}
imageline($im, $x1, 0 , $x1, 360, $grijs);
imagestring($im, 3, $x2, 370, $datum, $wit);
}
imageline ($im , 50, 0, 50, 360, $wit);
imageline ($im , 51, 0, 51, 360, $wit);
imageline ($im , 50, 360, 500, 360, $wit);
imageline ($im , 50, 361, 500, 361, $wit);
$datum = 0;
$max_key = 0;
foreach ($prices as $key => $price){
$max_key = $key;
}
foreach ($prices as $key => $price){
if ($verschil < 16){
$new_verschil = 16;
$start_y = 347 - 20 * $verschil;
}else{
$start_y = 27;
$new_verschil = $verschil;
}
$getal = 320/$new_verschil;
$price2 = $prices[$key+1];
$y1 = $start_y + ($hoogste-$price)*$getal;
$y2 = $start_y + ($hoogste-$price2)*$getal;
$x1 = 50 + ($datum * 20);
$x2 = 50 + (($datum + 1) * 20);
if ($key != $max_key){
imageline($im, $x1, $y1, $x2, $y2, $groen);
}
$datum++;
}
imagestring($im, 3, 180, 5, $naam, $wit);
imagepng($im);
imagedestroy($im);
?>
$all_prices = "100,150,175,100,200,210,200,150,155,164,143,154";
$naam = "Grafiek";
$prices = explode(",",$all_prices);
sort($prices);
$count = count($prices) - 1;
$laagste = $prices[0];
$hoogste = $prices[$count];
$verschil = $hoogste - $laagste;
if ($verschil < 16){
$stap = 1;
}else{
$stap = $verschil / 16;
}
$prices = explode(",",$all_prices);
header("Content-type: image/png");
$im = imagecreatetruecolor (500, 400);
$wit = imagecolorallocate($im, 255, 255, 255);
$zwart = imagecolorallocate($im, 0, 0, 0);
$grijs = imagecolorallocate($im, 70, 70, 70);
$groen = imagecolorallocate($im, 0, 255, 0);
#verticaal
if ($verschil < 16){
$new_hoogste = 16 + $laagste;
}else{
$new_hoogste = $hoogste;
}
imagestring($im, 3, 10, 20, $new_hoogste, $wit);
imagestring($im, 3, 10, 40, round(15 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 60, round(14 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 80, round(13 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 100, round(12 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 120, round(11 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 140, round(10 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 160, round(9 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 180, round(8 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 200, round(7 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 220, round(6 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 240, round(5 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 260, round(4 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 280, round(3 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 300, round(2 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 320, round(1 * $stap + $laagste), $wit);
imagestring($im, 3, 10, 340, $laagste, $wit);
imageline($im, 50, 27 , 500, 27 , $grijs);
imageline($im, 50, 47 , 500, 47 , $grijs);
imageline($im, 50, 67 , 500, 67 , $grijs);
imageline($im, 50, 87 , 500, 87 , $grijs);
imageline($im, 50, 107, 500, 107, $grijs);
imageline($im, 50, 127, 500, 127, $grijs);
imageline($im, 50, 147, 500, 147, $grijs);
imageline($im, 50, 167, 500, 167, $grijs);
imageline($im, 50, 187, 500, 187, $grijs);
imageline($im, 50, 207, 500, 207, $grijs);
imageline($im, 50, 227, 500, 227, $grijs);
imageline($im, 50, 247, 500, 247, $grijs);
imageline($im, 50, 267, 500, 267, $grijs);
imageline($im, 50, 287, 500, 287, $grijs);
imageline($im, 50, 307, 500, 307, $grijs);
imageline($im, 50, 327, 500, 327, $grijs);
imageline($im, 50, 347, 500, 347, $grijs);
#horizontaal - datum
for($i = 0; $i <= 22; $i++){
$x1 = 70 + 20 * $i;
$x2 = 45 + 20 * $i;
if (19 + $i > 30){
$datum = $i - 11;
}else{
$datum = 20 + $i;
}
imageline($im, $x1, 0 , $x1, 360, $grijs);
imagestring($im, 3, $x2, 370, $datum, $wit);
}
imageline ($im , 50, 0, 50, 360, $wit);
imageline ($im , 51, 0, 51, 360, $wit);
imageline ($im , 50, 360, 500, 360, $wit);
imageline ($im , 50, 361, 500, 361, $wit);
$datum = 0;
$max_key = 0;
foreach ($prices as $key => $price){
$max_key = $key;
}
foreach ($prices as $key => $price){
if ($verschil < 16){
$new_verschil = 16;
$start_y = 347 - 20 * $verschil;
}else{
$start_y = 27;
$new_verschil = $verschil;
}
$getal = 320/$new_verschil;
$price2 = $prices[$key+1];
$y1 = $start_y + ($hoogste-$price)*$getal;
$y2 = $start_y + ($hoogste-$price2)*$getal;
$x1 = 50 + ($datum * 20);
$x2 = 50 + (($datum + 1) * 20);
if ($key != $max_key){
imageline($im, $x1, $y1, $x2, $y2, $groen);
}
$datum++;
}
imagestring($im, 3, 180, 5, $naam, $wit);
imagepng($im);
imagedestroy($im);
?>