我试图使用php图形库在本地主机上显示一个简单图形。我的代码是:

include('phpgraphlib.php');
$graph = new PHPGraphLib(650,200);
$data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033,
"5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024,
"10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036,
"14" => .0028, "15" => .0025);
$graph->addData($data);
$graph->setTitle('PPM Per Container');
$graph->setBars(false);
$graph->setLine(true);
$graph->setDataPoints(true);
$graph->setDataPointColor('maroon');
$graph->setDataValues(true);
$graph->setDataValueColor('maroon');
$graph->setGoalLine(.0025);
$graph->setGoalLineColor('red');
$graph->createGraph();


但不幸的是,我的屏幕上没有显示图形。我已经检查了我对phpinfo的GD支持,它给了我以下结果

GD Support  enabled
GD Version  bundled (2.1.0 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.4.10
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support    enabled
libJPEG Version 8
PNG Support enabled
libPNG Version  1.2.50
WBMP Support    enabled
XPM Support enabled
libXpm Version  30411
XBM Support enabled


我的PHP版本是5.4.19,

我在这里做错了什么?请帮我

提前致谢

最佳答案

看来$ data数组是数字的。我建议像这样创建数组,而不是创建关联数组:

$data = array(.0032, .0028, .0021, .0033, .0034, .0031, .0036, .0027,
 .0024, .0021, .0026, .0024, .0036, .0028, .0025);


我在本地计算机上运行PHP 7.1,由于某些原因,PHPGraphLib无法渲染图形,因为我对$ data数组使用了关联数组。 PHP 5.4.45将使用关联数组呈现图形。它可能与每个版本如何识别或内部处理关联数组有关。

关于php - 即使启用了GD支持,也无法在localhost上显示图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23180446/

10-16 01:31
查看更多