<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');
require_once ('jpgraph/jpgraph_date.php');
require_once ('jpgraph/jpgraph_mgraph.php');


DEFINE('NDATAPOINTS',28000);
DEFINE('SAMPLERATE',300);

$start = time();
$end = $start+NDATAPOINTS*SAMPLERATE;
$xdata_pic = array();


//lecture data base
$db = mysql_connect('127.0.0.1', 'root', '');   // connexion
mysql_select_db('xfel',$db);                // selection 


//$req_pic    = mysql_query("SELECT Pic FROM power WHERE id_stand='b'and id_conditioning=208");// requetes
//$req_measure = mysql_query("SELECT hour FROM measure");
$req_hour_pic = mysql_query("SELECT measure.hour AS 'Date', power.Pic AS 'Pic' FROM measure INNER JOIN power ON (measure.id_measure=power.id_measure AND measure.id_conditioning=power.id_conditioning) WHERE measure.id_conditioning = 208 AND power.id_stand = 'b'");

// on fait une boucle qui va faire un tour pour chaque enregistrement
$index=0; 
while($data=mysql_fetch_assoc($req_hour_pic)) 
    { 
    $data_pic[$index] = $data['Pic'];
    $data_measure[$index] = $data['Date'];
    $index++;
    }

mysql_close($db);// fermeture connexion

for( $i=0; $i < $index; ++$i ) {
   $xdata[$i] = $data_measure[$i];
}

$xdata[$i] = $start + $i * SAMPLERATE;

//DEFINE('BKG_COLOR','lightgray:1.7');
DEFINE('BKG_COLOR','green:1.98');
DEFINE('WIND_HEIGHT',800);
DEFINE('WIND_WIDTH',250);


//------------------------------------------------------------------
// Setup the Pic graph
//------------------------------------------------------------------
$graph = new Graph(WIND_WIDTH,WIND_HEIGHT);
$graph->SetMarginColor(BKG_COLOR);
$graph->SetScale('datlin',0,1000);
$graph->Set90AndMargin(50,10,70,30);
$graph->SetFrame(true,'white',0);
$graph->SetBox();

$graph->title->Set('Pic');
$graph->title->SetColor('red');
$graph->title->SetFont(FF_FONT1,FS_BOLD,48);
$graph->title->SetMargin(5);

$graph->xaxis->SetFont(FF_FONT0,FS_NORMAL,9);

$graph->xaxis->SetTickLabels($xdata);

$graph->xgrid->Show();

$graph->yaxis->SetLabelAngle(90);
$graph->yaxis->SetColor('red');
$graph->yaxis->SetFont(FF_FONT0,FS_NORMAL,9);
$graph->yaxis->SetLabelMargin(0);
$graph->yaxis->scale->SetAutoMin(10);

$line = new LinePlot($data_pic);
$line->SetStepStyle();
$line->SetColor('red');

$graph->AddLine($line);

//-----------------------
// Create a multigraph
//----------------------
$mgraph = new MGraph();
$mgraph->SetMargin(2,2,2,2);
$mgraph->SetFrame(true,'darkgray',2);
$mgraph->SetFillColor(BKG_COLOR);
$mgraph->Add($graph,460,50);
$mgraph->title->Set('XFEL Banc B 20 Septembre 2013');
$mgraph->title->SetFont(FF_FONT2,FS_BOLD,80);
$mgraph->title->SetMargin(8);
$mgraph->Stroke();

?>
