gpt4 book ai didi

php - JpGraph 重叠图中的 x 轴刻度

转载 作者:行者123 更新时间:2023-11-29 21:12:48 26 4
gpt4 key购买 nike

我正在使用 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();

?>

我的问题是,x 轴上的比例与图表重叠。我想把它移低一点。问题图片:

enter image description here

最佳答案

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

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

关于php - JpGraph 重叠图中的 x 轴刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36224092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com