0

我正在尝试使用 Phpgraphlib 在我的网页上可视化图表。我使用以下代码:

PHP 脚本(graph.php):

<?php
include("phpgraphlib.php");
error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE);
$graph=new PHPGraphLib(550,350);

$link = mysql_connect('127.0.0.1', 'xxxx', 'xxxx') or die('Could not connect: ' . mysql_error());

mysql_select_db('quality') or die('Could not select database');

$dataArray=array();

//get data from database
$sql="SELECT country, tot_reg FROM ntr_perf_no_net WHERE data = '2016-09-05'";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
    while ($row = mysql_fetch_assoc($result)) {
        $country=$row["country"];
        $reg=$row["tot_reg"];
        //add to data areray
        $dataArray[$country]=$reg;
    }
}

//configure graph
$graph->addData($dataArray);
$graph->setTitle("Tot registration per Country");
$graph->setGradient("lime", "green");
$graph->setBarOutlineColor("black");
$graph->createGraph();
?>

网页(graph.html):

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Graph</title>
</head>
<body>
<h3>This is where I want to display my graph</h3>
<img src="graph.php" />
</body>
</html>

这很简单,但我收到 500 内部服务器错误。我知道服务器读取了 PHP 脚本(如果我在 PHP 脚本上放置了语义错误,我会在 apache 日志中看到它),所以我无法理解出了什么问题。SQL查询没问题,文件(Phpgraphlib.php、graph.html和graph.php)在同一个目录下,777权限(文件和目录)。

你能帮助我吗?

谢谢乔治

4

1 回答 1

0

我忘了安装GD。安装后,它开始工作。

于 2016-09-07T19:40:21.417 回答