source: code/Website/graph_bar.php@ 7878

Last change on this file since 7878 was 7878, 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 1 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
33//-- Y AXIS --\\
34
35$y = new y_axis();
36$y->set_range( 0, 50, 10 );
37$y->set_colour('#000000');
38$y->set_grid_colour('#D8D8D8');
39
40
41//-- X AXIS --\\
42
43$x = new x_axis();
44$x->colour('#000000')->grid_colour('#D8D8D8');
45$x_legend = new x_legend( 'Kamer nummer' );
46$x_legend->set_style( '{font-size: 14px; color: #000000}' );
47
48$x_labels = new x_axis_labels();
49$x_labels->set_colour( '#000000' );
50$x_labels->set_labels( $xaxis );
51$x->set_labels( $x_labels );
52
53
54
55//--CHART --\\
56
57$chart = new open_flash_chart();
58$chart->set_title( $title );
59$chart->set_x_legend( $x_legend );
60$chart->set_x_axis( $x );
61$chart->set_y_axis( $y );
62$chart->add_element( $bar );
63$chart->set_bg_colour( '#FFFFFF' );
64//$chart->add_element( $bar2 );
65
66echo $chart->toPrettyString();
67$chartwrite = $chart->toPrettyString();
68
69$fh = fopen("graphs/bar.txt", 'w') or die("can't open file");
70fwrite($fh, $chartwrite);
71fclose($fh);
72?>
Note: See TracBrowser for help on using the repository browser.