<?php
 // includovani potrebnych souboru lin a log jsou pro linearni a logaritmicke cary
include ("config.php");
include ("./jpg/src/jpgraph.php");
include ("./jpg/src/jpgraph_line.php");
 //include ("jpgraph_log.php");

 
 // pole dat ke kresleni
$i=0;
$aa=MySQL_Query("SELECT * FROM dostupnost WHERE id_server=$id_server ORDER BY time ");
while($bb=mysql_fetch_array($aa))
{
	$xdata[$i]=date("d/m",$bb["time"]);
	$ydata[$i]=$bb["dostupnost"];
	$i++;
}
$interval=3600;
$titulek=" Availability of server ".$nazev;
if (count($ydata)<2)
{
	$ydata = array(0,100);
	$titulek="Insufficiency of data for plot - ".$nazev;
}
//$datax=array("Jan","Feb","Mar","Apr","Maj","Jun","July","aug","Sep","Oct");

/*********** Vytvoreni grafu ************/
	$graph = new Graph(710,350);
	$graph->SetScale('textlin'); 
	 // nazev grafu a barva
	$graph->title->Set($titulek);
	$graph->title->SetFont(FF_FONT1,FS_BOLD);
	$graph->SetColor("white:1");
	 // okraje grafu levy pravy horni dolni a barva 
	$graph->img->SetMargin(80,90,30,40);
	$graph->SetMarginColor('white');
	 // kde bude legenda 
	$graph->legend->Pos(0.01,0.05,"right","center");
	$graph->legend->SetFillColor("white");
	 // vlozeni stinu pod graf
	$graph->SetShadow();
	 // vlozeni popisku do xove osy
	//$graph->xaxis->SetTickLabels($datax);

	 // mrizka na xove ose
	$graph->xgrid->Show(true,false);

/*********** Prvni cara ************/
	 // Popis os a nazev grafu

	$graph->xaxis->title->Set("Time [days]");
	//$graph->xaxis->SetTickLabels($procenta);
	$graph->xaxis->SetTickLabels($xdata);
	$graph->xaxis->SetTextTickInterval($interval); 
	$graph->yaxis->title->Set(" Availability of server [%]");//$graph->yaxis->SetTitle("Time [min]");

	 // Vzhled popisku os a nazvu grafu $graph->yaxis->title->Set("Usage of CPU [%]","low");
	$graph->yaxis->SetTitleMargin(50);
	$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
	$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
	 // barva a sirka ypilonove osy
	//$graph->yaxis->SetColor("blue");
	$graph->yaxis->SetWeight(2);
	 // kreleni mrizky
	$graph->ygrid->Show(true,true);

	 // nekresleni prvni nuly aby nespilvali s xovou nulou
	//	$graph->SetScale("intlin");

	//$graph->yaxis->SetTickLabels($procenta);
	//$graph->yaxis->SetTextTickInterval(4); 
	//$graph->yaxis->scale->SetAutoMin(0);
	$graph->yaxis->scale->SetGrace(0);
	//$graph->yaxis->scale->SetAutoMax(100);
	$graph->yaxis->scale->ticks->SupressFirst();
	 // vytvori novou instanci tridy lineplot malovani linearni cary vlozi tam data
	$lineplot=new LinePlot($ydata);
	 //legenda
	$lineplot->SetLegend("Availability");
	 // nastavi barvu a tloustku kreslene cary 
	$lineplot->SetColor("green:0.6");
	$lineplot->SetWeight(2);  // Two pixel wide
	//$lineplot->SetFillColor("orange");
	 // vykresleni cary
	$graph->Add($lineplot);
	
/******* Zobrazeni grafu ************/
	 // Zobraz graf
	$graph->Stroke();

?>