<?php // content="text/plain; charset=utf-8"
include("../utils/phpgraphlib.php");
require_once("../classes/Mysql.php");

$m = new Mysql();
$dataArray_elektrina=array();
  
  
  
//get data from database
$sql="SELECT * FROM `spotreba` ORDER BY date DESC";
$result = $m->dotaz($sql) or die('Query failed: ' . mysql_error());
if ($result) {
  //$i = 0;
  while ($row = $m->podejRadek($result)) {
      $temp = date("d",strtotime($row->date));
      $up = $row->kwh;
      $vysledek = $m->podejRadek($result);
      while(date("d",strtotime($vysledek->date)) == $temp){
         $down = $vysledek->kwh;
         $date = $vysledek->date;   
         $vysledek = $m->podejRadek($result); 
      }
      $kwh = $up - $down;
      $dataArray_elektrina[$date]=$kwh;      
  }
}



//date("d.m",strtotime($date))        

include('phpgraphlib.php');
$graph = new PHPGraphLib(650, 200);
$graph->addData($dataArray_elektrina);
$graph->setBarColor('navy');
$graph->setupXAxis(20, 'blue');
$graph->setTitle('Spotreba elektriny za posledni mesic');
$graph->setTitleColor('black');
$graph->setGridColor('153,204,255');
//$graph->setDataValues(true);
//$graph->setDataValueColor('navy');
//$graph->setGoalLineColor('red');
$graph->createGraph();


?>


