<?php
include_once 'php-ofc-library/open-flash-chart.php';
include_once 'cfg/mysql.php';
connectdb();


$result = mysql_query("select AVG(value) AS average FROM tuples LEFT JOIN sensors ON tuples.sensorID=sensors.sensorID WHERE end IS NULL GROUP BY sensors.roomID");

$data = array();
while($row = mysql_fetch_array($result))
{
  $data[] = intval($row['average']);
}

$title = new title( 'All rooms' );

$bar = new bar();
$bar->colour( '#BF3B69');
$bar->key('Gemiddelde', 14);
$bar->set_values( $data );
$bar->set_on_click("bar_1");
$bar->set_colour('#f7921c');


//-- Y AXIS --\\

$y = new y_axis();
$y->set_range( 0, 50, 10 );
$y->set_colour('#000000');
$y->set_grid_colour('#D8D8D8');


//-- X AXIS --\\

$x = new x_axis();
$x->colour('#000000')->grid_colour('#D8D8D8');
$x_legend = new x_legend( 'Kamer ID' );
$x_legend->set_style( '{font-size: 14px; color: #000000}' );


//--CHART --\\

$chart = new open_flash_chart();
$chart->set_title( $title );
$chart->set_x_legend( $x_legend );
$chart->set_x_axis( $x );
$chart->set_y_axis( $y );
$chart->add_element( $bar );
$chart->set_bg_colour( '#FFFFFF' );
//$chart->add_element( $bar2 );


echo $chart->toString();
?>