1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_stock.php');
mysql_connect("localhost", "root", "") or
die("Impossible de se connecter : " . mysql_error());
mysql_select_db("graphique");
//query candle stick
$result = mysql_query("SELECT Open_Period as iOpen, Close_Period as iClose, high as ihigh, low as ilow from jpgraph ");
//query total id
$resultTotal = mysql_query("SELECT COUNT(id) as totalID from jpgraph");
//initialisation des tableaux à vide
$datay = array();
//boucle chandelier
while ($row = mysql_fetch_assoc($result)) {
$datay[] = $row['iOpen'];
$datay[] = $row['iClose'];
$datay[] = $row['ilow'];
$datay[] = $row['ihigh'];
}
//boucle total id
while ($rowTotal = mysql_fetch_assoc($resultTotal)) {
$totalData = $rowTotal['totalID'];
}
//width
$width = ($totalData * 20);
// Setup a simple graph
$graph = new Graph($width,500, 'auto');
//$graph->SetImgFormat('png',5);
$graph->SetScale("textlin");
$graph->SetMarginColor('lightblue');
//$graph->title->Set('Stockchart example');
$graph->img->SetMargin(35,10,10,20);
// Create a new stock plot
$p1 = new StockPlot($datay);
//$p1->SetColor('black','blue','black','red');
// Width of the bars (in pixels)
$p1->SetWidth(4);
// Uncomment the following line to hide the horizontal end lines
$p1->HideEndLines();
// Add the plot to the graph and send it back to the browser
$graph->Add($p1);
$graph->Stroke(); |
Partager