无法使用自动缩放,因为无法确定 PHP 中 Y 轴的有效最小/最大值



当我通过本地主机执行我的PHP代码时,我收到此错误。我使用jpgraph库来绘制。它连接到我的总是数据数据库,错误说:

它无法使用自动缩放,因为无法确定 Y 轴的有效最小/最大值(仅 NULL 值(。

这是我的PHP代码

<?php // content="text/plain; charset=utf-8"
require_once('connectDBalwaysdata.inc.php');
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_bar.php');

$query = "SELECT * FROM `transactions`;";
$result = mysqli_query($link,$query);
$nums = [];
$categories = [];
$num_of_used = array_fill(0,15,0);

while ( $row = mysqli_fetch_assoc($result) ){
$IdCategory         = $row['idCategory'];
$query_category     = "SELECT category FROM `categories` WHERE idCategory='{$IdCategory}'";
$result_category    = mysqli_query($link, $query_category);
$data_category      = mysqli_fetch_assoc($result_category);
array_push($categories,$data_category['category']);
$num_of_used[ $row['idCategory']-1 ]++;
array_push($nums,$num_of_used);
}

$graph = new Graph(500,300,'auto');
$graph->SetScale("textlin");
$theme_class = new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->yaxis->SetTickPositions(array(0,10,20,30,40,50,60),array(5,15,25,35,45,55));
$graph->SetBox(false);

$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels($categories);
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$b1plot = new BarPlot($nums);

$graph->Add($b1plot);

$b1plot->SetColor("white");
$b1plot->SetWidth(45);
$graph->title->Set("Categories of Transactions");

$graph->Stroke();
?>

同样的问题发生在我身上,请在您的电话中尝试此操作SetScale()

$graph->SetScale("textlin",0,65);

显然,您可以使用不同的范围值,但对我来说,关键是定义 0

相关内容

最新更新