2016-03-25 41 views
0

我使用JpGraph和PHP生成图表。我想显示一段时间的温度。代码是:JpGraph xaxis scale在重叠图表

<?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(); 

?> 

我的问题是,xaxis上的比例与图形重叠。我想稍微调低一点。 形象的问题:

enter image description here

回答

0

我解决了自己的问题。如果有人有兴趣,我不得不添加一行:

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