JpGraph xaxis重叠图表中的比例

时间:2016-03-25 16:39:40

标签: php mysql jpgraph

我使用JpGraph和PHP生成图表。我想随着时间的推移显示温度。代码是:

<?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

1 个答案:

答案 0 :(得分:0)

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

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