cirkeldiagram

Gesponsorde koppelingen

PHP script bestanden

  1. cirkeldiagram

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
//--- Colours
//--- Function to switch html to rgb

function html2rgb( $color = '000000' )
{

    // Gevonden via Google, deze is dus NIET van mij.
    if ($color[0] == '#')
    {

        $color = substr($color, 1);
    }

    
    $length = strlen( $color );
    if ( $length == 6 )
    {

        list($r, $g, $b) = array(
            $color[0].$color[1],
            $color[2].$color[3],
            $color[4].$color[5]);
    }

    elseif ( $length == 3 )
    {

        list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
    }

    else
    {
        return false;
    }


    $r = hexdec( $r );
    $g = hexdec( $g );
    $b = hexdec($b);
    
    return array($r, $g, $b);
}


$colors = array(
    'FFFAFA',
    'F8F8FF',
    'F5F5F5',
    'DCDCDC',
    'FFFAF0',
    'FDF5E6',
    'FAF0E6',
    'FAEBD7',
    'FFEFD5',
    'FFEBCD',
    'FFE4C4',
    'FFDAB9',
    'FFDEAD',
    'FFE4B5',
    'FFF8DC',
    'FFFFF0',
    'FFFACD',
    'FFF5EE',
    'F0FFF0',
    'F5FFFA',
    'F0FFFF',
    'F0F8FF',
    'E6E6FA',
    'FFF0F5',
    'FFE4E1',
    '000000',
    '2F4F4F',
    '696969',
    '708090',
    '778899',
    'BEBEBE',
    'D3D3D3',
    '191970',
    '000080',
    '6495ED',
    '483D8B',
    '6A5ACD',
    '7B68EE',
    '8470FF',
    '0000CD',
    '4169E1',
    '0000FF',
    '1E90FF',
    '00BFFF',
    '87CEEB',
    '4682B4',
    'B0C4DE',
    'ADD8E6',
    'B0E0E6',
    'AFEEEE',
    '00CED1',
    '48D1CC',
    '40E0D0',
    '00FFFF',
    'E0FFFF',
    '5F9EA0',
    '66CDAA',
    '7FFFD4',
    '006400',
    '556B2F',
    '8FBC8F',
);

/* Meer kleuren? http://catless.ncl.ac.uk/Lindsay/swatch1.html (Swatch 1 tot 8)
-------------------------------------------------------------------------------------------- */

//--- Uniek!

$colors = array_unique( $colors );

function
getRandomcolor()
{

    global $used_colours, $img, $colors;
    
    $rand = rand(0, ( count( $colors ) - 1 ) );
    $color = $colors[$rand];
    
    if ( in_array( $rand, $used_colours ) )
    {

        return getRandomcolor();
    }

    else
    {
        $used_colours[] .= $rand;
    }

    
    list( $r, $g, $b ) = html2rgb( $color );
    return imagecolorallocate( $img, $r, $g, $b );
}

function
h2r( $color = '000000')
{

    return html2rgb( $color );
}


//--- Get stats to fix circle diagram with
if ( $_GET['stats'] == '' && $_GET['stats'] == NULL )
{

    exit( 'Sorry, geen opties gevonden! (Geef deze zo op: "' . $_SERVER['PHP_SELF'] . '?stats=Peren-500;Appels-300;Bananen-200&side=300")' );
}

else
{
    $explode = explode(';', $_GET['stats'] );
    if ( is_array( $explode ) )
    {

        $input_stats = array();
        foreach( $explode as $value )
        {

            list( $key, $val ) = explode('-', $value );
            $input_stats[$key] = $val;
        }

        $options = @count( $input_stats );
        if ( $options < 1 )
        {

            exit( 'Sorry, geen opties gevonden! (Geef deze zo op: "' . $_SERVER['PHP_SELF'] . '?stats=Peren-500;Appels-300;Bananen-200&side=300")' );
        }
    }

    else
    {
        exit( 'Sorry, geen opties gevonden! (Geef deze zo op: "' . $_SERVER['PHP_SELF'] . '?stats=Peren-500;Appels-300;Bananen-200&side=300")' );
    }
}


foreach( $input_stats as $key => $value )
{

    if ( ( $key == '' && $key == NULL ) OR ( $value == '' && $value == NULL ) )
    {

        exit( 'Sorry, geen opties gevonden! (Geef deze zo op: "' . $_SERVER['PHP_SELF'] . '?stats=Peren-500;Appels-300;Bananen-200")' );
    }

    
    if ( !is_numeric( $value ) )
    {

        exit( 'Het aantal moet een nummer zijn (Was ' . $value . ')' );
    }
}

$side = ( $_GET['side'] != '' && $_GET['side'] != NULL && is_numeric( $_GET['side'] ) && $_GET['side'] > 0 && $_GET['side'] < 400 ) ? $_GET['side'] : 200;
$height = $side + ( $options * 25 );

$width = ( $side < 300 ) ? 300 : $side;

//--- Create image stream
$img = @imagecreate( $width, $height ) or exit( 'Failed creating image' );

//--- Background color (white)
list( $r, $g, $b ) = h2r( 'FFFFFF' );
$background_color = imagecolorallocate($img, $r, $g, $b );

$stats = array();

$totaal = 0;
foreach( $input_stats as $value )
{

    $totaal = $totaal + $value;
}


$id = 0;
foreach( $input_stats as $name => $stat )
{

    $procent = $stat / $totaal * 100;
    $start = 0 + $eind;
    $eind = 0 + $start + ( $procent * 3.6 );
    $stats[$id] = array(
        'object_naam'    => $name,
        'aantal'        => $stat,
        'procenten'        => $procent,
        'start'            => $start,
        'eind'            => $eind,
    );

    $id++;
}


//--- Create blocks
$zwart = imagecolorallocate($img, 0, 0, 0);
$arc = imagefilledarc($img, ( $side / 2 ), ( $side / 2 ), $side - 15, $side - 15, 0, 360, $zwart, IMG_ARC_PIE );
$i = 0;
$font = './Verdana.ttf';
$used_colours = array();
foreach( $stats as $name => $stat )
{

    $colour = getRandomcolor();
    $arc = imagefilledarc($img, ( $side / 2 ), ( $side / 2 ), $side - 15, $side - 15, $stat['start'], $stat['eind'], $colour, IMG_ARC_PIE );
    // Give the information below the diagramm
    $x_top = $side + ( $i * 20 );
    imagefilledrectangle($img, 40, $x_top, 50, $x_top + 10, $colour );
    imagettftext($img, 10, 0, 60, $x_top + 10, imagecolorallocate($img, 0, 0, 0), $font, $stat['aantal'] . ' ' .$stat['object_naam'] );
    $i++;
    if ( count( array_unique( array_merge( $used_colours, $colors ) ) ) == count( $colors ) )
    {

        //--- Alle kleuren gebruikt, nieuwe loop
        $used_colours = array();
    }
}


//--- Create image
header( 'Content-type: image/png' );
imagepng( $img );
imagedestroy( $img );
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.