2016-03-25 10 views
0

私はチャートを生成するためにJpGraphとPHPを使用しています。時間をかけて温度を表示したい。コードは次のとおりです。JpGraph xaxisオーバーラップチャートの縮尺

<?php 
require_once ('jpgraph/jpgraph.php'); 
require_once ('jpgraph/jpgraph_line.php'); 
require_once("jpgraph/jpgraph_date.php"); 


$servername = "localhost"; 
$username = "root"; 
$password = "*********"; 
$db_name = "temperatures"; 


$conn = new PDO("mysql:host=$servername;dbname=$db_name", $username, $password); 
// set the PDO error mode to exception 
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

$query_temp = "SELECT * FROM `INSIDE` ORDER BY `INSIDE`.`ID` DESC LIMIT 0 , 30"; 
$temp = $conn -> query($query_temp); 
$temp_final = $temp -> fetchALL(PDO::FETCH_ASSOC); 

$xdata = array(); 
$ydata = array(); 

for($x = 0; $x < 30; $x++) { 
    $datetime_unix = strtotime($temp_final[$x]["DATE"] . $temp_final[$x]["TIME"]); 
    $xdata[] = $datetime_unix; 
} 

for($x = 0; $x < 30; $x++) { 
    $ydata[] = $temp_final[$x]["VALUE"]; 
} 

// Size of the overall graph 
$width=1800; 
$height=900; 

// Create the graph and set a scale. 
// These two calls are always required 
$graph = new Graph($width,$height); 
$graph->SetScale('datelin'); 

$graph -> yaxis -> title -> set("Temperature C"); 
$graph -> xaxis -> title -> set(""); 
$graph->yaxis->title->SetFont(FF_FONT2); 
$graph -> xaxis -> title -> SetFont(FF_FONT2); 
$graph->xaxis->SetLabelAngle(45); 
$graph->xaxis->scale->SetDateFormat('H:i d.m.Y'); 
$graph->SetMargin(50,10,40,100); 

// Create the linear plot 
$lineplot=new LinePlot($ydata, $xdata); 

// Add the plot to the graph 
$graph->Add($lineplot); 

// Display the graph 
$graph->Stroke(); 

?> 

私の問題は、グラフが重なっていることです。私はそれを少し下に移動したいと思います。問題の 画像:

enter image description here

答えて

0

私はこの問題を自分で解決しました。誰かが興味があれば、私は1行追加しなければならなかった:

$graph->xaxis->SetPos('min');