DataValues in PHPGraphLib op de voorgrond zetten

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Jelle Botman

Jelle Botman

29/05/2015 11:56:41
Quote Anchor link
ik wil de datavalues op de voorgrond krijgen in mijn grafiek, ze staan nu op de achtergrond.
hoe krijg ik ze op de voorgrond?
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
<?php
require('phpgraphlib.php');
include('phpgraphlib_stacked.php');
date_default_timezone_set('Europe/Amsterdam');
// DB connection
$username = "root";
$password = "usbw";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
mysql_select_db("trikx") ;
$graph = new PHPGraphLibStacked(1800,500);
$data = unserialize(urldecode(stripslashes($_GET['mydata'])));
$data1 = unserialize(urldecode(stripslashes($_GET['mydata1'])));
$data2 = unserialize(urldecode(stripslashes($_GET['mydata2'])));
$naam = $_GET['naam'];

// $graph->setBars(false);
// $graph->setLine(true);

$graph->setBarColor('green', 'yellow', 'red');
$graph->setTitle($naam);

$graph->addData($data, $data1, $data2);
$graph->setDataValues(true);
$graph->setGrid(false);
$graph->setLegend(true);
$graph->setTitleLocation('left');
$graph->setXValuesHorizontal(true);

$graph->setLegendOutlineColor('white');
$graph->setLegendTitle('Actief', 'Nieuw', 'Opgeheven');

$graph->createGraph();








?>
[/CODE]



en dit is de settings file van de grafiek:

[CODE]
<?php
////////////////////////////////////////////////////////////////////////
//PHPGraphLib -  PHP Graphing Library v2.31 - Stacked Bar Extension   //
//Author: Elliott Brueggeman                                          //
//PHP v4.04 + compatible                                              //
//Please visit www.ebrueggeman.com for usage policy                   //
//and documentation + examples                                        //
////////////////////////////////////////////////////////////////////////

class PHPGraphLibStacked extends PHPGraphLib {
    function
PHPGraphLibStacked($width = '', $height = ''){
        PHPGraphLib::PHPGraphLib($width,$height);    
    }
    function
generateBars() {
        $this->finalizeColors();
        $barCount = 0;
        $adjustment = 0;
        $last_y1 = array();
        $last_y2 = array();
        if ($this->bool_user_data_range && $this->data_min >= 0) {
            $adjustment = $this->data_min * $this->unit_scale;
        }

        $this->data_array = array_reverse($this->data_array);
        foreach ($this->data_array as $data_set_num => $data_set) {
            $lineX2 = NULL;
            $xStart = $this->y_axis_x1 + ($this->space_width / 2);
            foreach ($data_set as $key => $item) {
                $hideBarOutline = false;
                $x1 = round($xStart);
                $x2 = round($xStart + $this->bar_width);
                if ($data_set_num > 0) {
                    //find last set valid value for this dataset incase prior values were not set
                    $found = false;
                    $i = 1;
                    //default last to base in case none are found
                    $last = $this->x_axis_y1;
                    while ($found == false && ($data_set_num - $i) >= 0) {
                        if (isset($last_y1[$data_set_num - $i][$key])) {
                            $last = $last_y1[$data_set_num - $i][$key];
                            $found = true;
                        }

                        $i++;
                    }

                    $y2 = round($last);
                    $y1 = round(($y2 - ($item * $this->unit_scale) + $adjustment));
                }

                else {
                    $y2 = round($this->x_axis_y1);
                    $y1 = round((($this->x_axis_y1 - ($item * $this->unit_scale) + $adjustment)));
                }

                //if we are using a user specified data range, need to limit what's displayed
                if ($this->bool_user_data_range) {
                    if ($item <= $this->data_range_min) {
                        //don't display, we are out of our allowed display range!
                        $y1 = $y2;
                        $hideBarOutline = true;
                    }

                    else if ($item >= $this->data_range_max) {
                        //display, but cut off display above range max
                        $y1 = $this->x_axis_y1 - ($this->true_displayed_max_value * $this->unit_scale) + $adjustment;    
                    }
                }

                //draw bar and outline if nonzero
                if ($this->bool_bars && $item != 0) {
                    if ($this->bool_gradient) {
                        $this->drawGradientBar($x1, $y1, $x2, $y2, $this->multi_gradient_colors_1[$data_set_num], $this->multi_gradient_colors_2[$data_set_num], $data_set_num);
                    }

                    else {
                        imagefilledrectangle($this->image, $x1, $y1,$x2, $y2,  $this->multi_bar_colors[$data_set_num]);
                    }

                    //draw bar outline
                    if ($this->bool_bar_outline && !$hideBarOutline) {
                        imagerectangle($this->image,  $x1, $y1, $x2, $y2, $this->outline_color);
                    }
                }

                // display data values
                if ($this->bool_data_values) {
                    $dataX = ($x1 + ($this->bar_width) / 1000) - ((strlen($item) * $this->data_value_text_width) / 2);
                    //value to be graphed is equal/over 0
                    if ($item >= 0) {
                        $dataY=$y1-$this->data_value_padding-$this->data_value_text_height;
                    }

                    else {
                        //check for item values below user spec'd range
                        if ($this->bool_user_data_range && $item <= $this->data_range_min) {
                            $dataY = $y1 - $this->data_value_padding - $this->data_value_text_height;
                        }

                        else {
                            $dataY = $y1 + $this->data_value_padding;
                        }
                    }

                    //add currency sign, formatting etc
                    if ($this->data_format_array) {
                        $item = $this->applyDataFormats($item);
                    }

                    if ($this->data_currency) {
                        $item = $this->applyDataCurrency($item);
                    }

                    //recenter data position if necessary
                    $dataX -= ($this->data_additional_length * $this->data_value_text_width) / 2;
                    imagestring($this->image, 3, $dataX, $dataY, $item,  $this->data_value_color);
                }

                //write x axis value
                if ($this->bool_x_axis_values) {
                    if ($data_set_num == $this->data_set_count - 1) {
                        if ($this->bool_x_axis_values_vert) {
                            if ($this->bool_all_negative) {
                                //we must put values above 0 line
                                $textVertPos = round($this->y_axis_y2 - $this->axis_value_padding);
                            }

                            else {
                                //mix of both pos and neg numbers
                                //write value y axis bottom value (will be under bottom of grid even if x axis is floating due to

                                $textVertPos = round($this->y_axis_y1 + (strlen($key) * $this->text_width) + $this->axis_value_padding);
                            }

                            $textHorizPos = round($xStart + ($this->bar_width / 2) - ($this->text_height / 2));
                            imagestringup($this->image, 2, $textHorizPos, $textVertPos, $key,  $this->x_axis_text_color);
                        }

                        else {
                            if ($this->bool_all_negative) {
                                //we must put values above 0 line
                                $textVertPos = round($this->y_axis_y2 - $this->text_height - $this->axis_value_padding);
                            }

                            else {
                                //mix of both pos and neg numbers
                                //write value y axis bottom value (will be under bottom of grid even if x axis is floating

                                $textVertPos=round($this->y_axis_y1 + ($this->text_height * 2 / 3)-$this->axis_value_padding);
                            }

                            //horizontal data keys
                            $textHorizPos = round($xStart + ($this->bar_width / 2) - ((strlen($key) * $this->text_width) / 2));
                            imagestring($this->image, 2, $textHorizPos, $textVertPos, $key,  $this->x_axis_text_color);
                        }
                    }
                }

                $xStart += $this->bar_width + $this->space_width;
                $last_y1[$data_set_num][$key] = $y1;
            }
        }
    }
    function
addData($data, $data2 = '', $data3 = '', $data4 = '', $data5 = '') {
        if (is_array($data)){ $this->data_array[]=$data; }
        if (is_array($data2)){ $this->data_array[]=$data2; }
        if (is_array($data3)){ $this->data_array[]=$data3; }
        if (is_array($data4)){ $this->data_array[]=$data4; }
        if (is_array($data5)){ $this->data_array[]=$data5; }
        //assess data
        $min = $this->data_max_allowable;
        $max = $this->data_min_allowable;
        $this->data_count=0;
        $key_max = array();
        //loop through each row, adding values to keyed arrays to find combined max
        foreach ($this->data_array as $data_set_num => $data_set) {
            foreach ($data_set as $key => $item) {
                if (!is_numeric($item)) {
                    unset($this->data_array[$data_set_num][$key]);
                }

                else {
                    $key_max[$key] = isset($key_max[$key]) ? $key_max[$key] + $item : $item;
                    if($key_max[$key] < $min){ $min = $key_max[$key]; }
                    if($key_max[$key] > $max){ $max = $key_max[$key]; }
                }
            }

            //find the count of the dataset with the most data points
            $count = count($this->data_array[$data_set_num]);
            $count > $this->data_count ? $this->data_count = $count : NULL;
        }

        //number of valid data sets
        $this->data_set_count = count($this->data_array);
        if ($this->data_set_count == 0) {
            $this->error[] = "No valid datasets added in adddata() function.";
        }

        else {
            $this->calcMinMax($min, $max);
        }
    }
    
}

?>
Gewijzigd op 29/05/2015 11:58:22 door Jelle Botman
 
Er zijn nog geen reacties op dit bericht.



Overzicht Reageren

 
 

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.