2016-03-25 11 views
0

Ich benutze JpGraph und PHP, um ein Diagramm zu generieren. Ich möchte die Temperatur im Laufe der Zeit zeigen. Der Code ist:JpGraph xaxis skalieren in Überlappungen Diagramm

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

?> 

Mein Problem ist, dass der Maßstab auf der Xaxis den Graphen überlappt. Ich würde es gerne ein wenig nach unten verschieben. Bild des Problems:

enter image description here

Antwort

0

Ich löste das Problem selbst. Wenn jemand interessiert ist, musste ich eine Zeile hinzufügen:

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