JPGraph 错误,绘图具有非法比例

JPGraph error, A plot has an illegal scale

我正在尝试使用 JPGragph 制作图表,但我一直收到一条错误消息:

JpGraph Error A plot has an illegal scale. This could for example be that you are trying to use text auto scaling to draw a line plot with only one point or that the plot area is too small. It could also be that no input data value is numeric (perhaps only '-' or 'x')

$ydata = round($ydata[0]); // An attempt to convert float to int
$ydata = (int)$ydata; // That didn't bring any solution(thought it couldn't handle float)

$pt = new LinePlot($ydata); // Here is where the error is thrown
$bar2->Add($pt);
$pt->SetColor("blue");
$pt->SetWeight(10);

我尝试用整数替换 $ydata,但这只会引发致命错误。

没有舍入和类型转换,这是 $ydata 的 var_dump:

array(1) { [0]=> float(8.1102970953135) }

与 PHP 7 合作?我遇到了同样的错误并发现了这个:

http://jpgraph.net/doc/faq.php#F4-13

他们说您的 PHP 安装是 "faulty"。

对我有帮助的是向数据数组添加第二个值 - 只有一个值不起作用。

当绘图仅包含一个数据点时,我在使用 PHP 7.2 时遇到了同样的问题。 原因似乎是 JPGraph 试图将单个数据点同时放在绘图的左侧和右侧边缘。

使用 $plot->SetCenter(); 解决了我的问题,箱线图看起来更好。