[7849] | 1 | <?php
|
---|
| 2 | include_once 'php-ofc-library/open-flash-chart.php';
|
---|
| 3 | include_once 'cfg/mysql.php';
|
---|
| 4 | connectdb();
|
---|
| 5 |
|
---|
| 6 |
|
---|
[7878] | 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;");
|
---|
[7849] | 15 |
|
---|
| 16 | $data = array();
|
---|
| 17 | while($row = mysql_fetch_array($result))
|
---|
| 18 | {
|
---|
| 19 | $data[] = intval($row['average']);
|
---|
[7878] | 20 | $xaxis[] = ($row['xaxis']);
|
---|
[7849] | 21 | }
|
---|
| 22 |
|
---|
[7878] | 23 | $title = new title( 'Alle kamers' );
|
---|
[7849] | 24 |
|
---|
| 25 | $bar = new bar();
|
---|
| 26 | $bar->colour( '#BF3B69');
|
---|
[7878] | 27 | $bar->key('Gemiddelde energieverbruik van gisteren in Watt', 14);
|
---|
[7849] | 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');
|
---|
[7878] | 45 | $x_legend = new x_legend( 'Kamer nummer' );
|
---|
[7849] | 46 | $x_legend->set_style( '{font-size: 14px; color: #000000}' );
|
---|
| 47 |
|
---|
[7878] | 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 );
|
---|
[7849] | 52 |
|
---|
[7878] | 53 |
|
---|
| 54 |
|
---|
[7849] | 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 |
|
---|
[7878] | 66 | echo $chart->toPrettyString();
|
---|
| 67 | $chartwrite = $chart->toPrettyString();
|
---|
[7849] | 68 |
|
---|
[7878] | 69 | $fh = fopen("graphs/bar.txt", 'w') or die("can't open file");
|
---|
| 70 | fwrite($fh, $chartwrite);
|
---|
| 71 | fclose($fh);
|
---|
[7849] | 72 | ?>
|
---|