source: code/Website/script_bar.php@ 7887

Last change on this file since 7887 was 7887, checked in by dennisw, 15 years ago
File size: 1.8 KB
Line 
1<?php
2include_once 'php-ofc-library/open-flash-chart.php';
3include_once 'cfg/mysql.php';
4connectdb();
5
6
7$result = mysql_query("
8 select AVG(`tuples`.value) AS average, `rooms`.name AS xaxis
9 FROM (`save_energy`.`tuples`)
10 JOIN `save_energy`.`sensors` ON (`tuples`.sensorID=`sensors`.sensorID)
11 JOIN `save_energy`.`rooms` ON (`sensors`.roomID=`rooms`.roomID)
12 WHERE `sensors`.name LIKE '%power'
13 AND DATE(`tuples`.start) = CURRENT_DATE() - INTERVAL 47 DAY
14 GROUP BY `rooms`.name;");
15
16$data = array();
17while($row = mysql_fetch_array($result))
18{
19 $data[] = intval($row['average']);
20 $xaxis[] = ($row['xaxis']);
21}
22
23$title = new title( 'Alle kamers' );
24
25$bar = new bar();
26$bar->colour( '#BF3B69');
27$bar->key('Gemiddelde energieverbruik van gisteren in Watt', 14);
28$bar->set_values( $data );
29$bar->set_on_click("bar_1");
30$bar->set_colour('#f7921c');
31
32//-- Y AXIS --\\
33
34$y = new y_axis();
35$y->set_range( 0, 50, 10 );
36$y->set_colour('#000000');
37$y->set_grid_colour('#D8D8D8');
38
39
40//-- X AXIS --\\
41
42$x = new x_axis();
43$x->colour('#000000')->grid_colour('#D8D8D8');
44$x_legend = new x_legend( 'Kamer nummer' );
45$x_legend->set_style( '{font-size: 14px; color: #000000}' );
46
47$x_labels = new x_axis_labels();
48$x_labels->set_colour( '#000000' );
49$x_labels->set_labels( $xaxis );
50$x->set_labels( $x_labels );
51
52
53
54//--CHART --\\
55
56$chart = new open_flash_chart();
57$chart->set_title( $title );
58$chart->set_x_legend( $x_legend );
59$chart->set_x_axis( $x );
60$chart->set_y_axis( $y );
61$chart->add_element( $bar );
62$chart->set_bg_colour( '#FFFFFF' );
63
64echo $chart->toPrettyString();
65$chartwrite = $chart->toPrettyString();
66
67$fh = fopen("graphs/bar.txt", 'w') or die("can't open file");
68fwrite($fh, $chartwrite);
69fclose($fh);
70?>
Note: See TracBrowser for help on using the repository browser.