PHPGraphlib太多Datapoints

时间:2014-06-19 14:26:50

标签: php phpgraphlib

我试图根据他们进入的月份/年份从我们的服务台软件创建我们所有门票的图表。我已经对数据库运行了查询,并且正好得到我所做的事情。我正在寻找。

我发现PHPGraphlib根据输入的数组生成图表。但是,我得到的常数错误是Graph太小或太多数据点。

错误: enter image description here

我知道它正确生成了数组,因为我可以通过以下方式查看内容:

print_r($data);

输出print_r($ data);

Array ( [March 2012] => 10 [April 2012] => 18 [May 2012] => 20 [June 2012] => 19 [July 2012] => 10 [August 2012] => 22 [September 2012] => 18 [October 2012] => 17 [November 2012] => 15 [December 2012] => 12 [January 2013] => 24 [February 2013] => 18 [March 2013] => 33 [April 2013] => 13 [May 2013] => 20 [June 2013] => 20 [July 2013] => 21 [August 2013] => 13 [September 2013] => 15 [October 2013] => 14 [November 2013] => 14 [December 2013] => 3 [January 2014] => 13 [February 2014] => 15 [March 2014] => 23 [April 2014] => 20 [May 2014] => 33 [June 2014] => 19 )

<?php
include("../phpgraphlib.php");
$graph = new PHPGraphLib(1000,1000);
include 'db.inc';

$sql="SELECT FROM_UNIXTIME(swtickets.dateline,'%M %Y') AS Month, Count(DISTINCT(ticketmaskid)) AS Count FROM swtickets GROUP BY FROM_UNIXTIME(swtickets.dateline,'%M %Y') ORDER BY FROM_UNIXTIME(swtickets.dateline,'%Y'), FROM_UNIXTIME(swtickets.dateline,'%m') ASC";
$result=mysql_query($sql);

$data = array();
$num=mysql_numrows($result);
$i=0;

while ($i < $num){
    $mon=mysql_result($result,$i,"Month");
    $co=mysql_result($result,$i,"Count");
    $data[$mon]=$co;
    $i++;
}

mysql_close();
$graph->addData($data);
$graph->setBarColor('255,255,204');
$graph->setTitle('Money Made at XYZ Corp');
$graph->setTextColor('gray');
$graph->createGraph();

?>

我还尝试将我的查询限制为仅包含1个数据点,但仍然会产生相同的错误。

如果我手动创建数组,它不会生成错误并按预期生成图形。

<?php
include("../phpgraphlib.php");
$graph = new PHPGraphLib(5000,5000);

$data = array(    
    "March 2012" => "10",
    "April 2012" => "18",
    "May 2012" => "20",
    "June 2012" => "19",
    "July 2012" => "10",
    "August 2012" => "22",
    "September 2012" => "18",
    "October 2012" => "17",
    "November 2012" => "15",
    "December 2012" => "12",
    "January 2013" => "24",
    "February 2013" => "18",
    "March 2013" => "33",
    "April 2013" => "13",
    "May 2013" => "20",
    "June 2013" => "20",
    "July 2013" => "21",
    "August 2013" => "13",
    "September 2013" => "15",
    "October 2013" => "14",
    "November 2013" => "14",
    "December 2013" => "3",
    "January 2014" => "13",
    "February 2014" => "15",
    "March 2014" => "23",
    "April 2014" => "20",
    "May 2014" => "33",
    "June 2014" => "19",
);

$graph->addData($data);
$graph->setBarColor('255,255,204');
$graph->setTitle('Money Made at XYZ Corp');
$graph->setTextColor('gray');
$graph->createGraph();
?>

输出页面:我已经在标准的PHP页面和HTML页面上尝试过它但是会收到相同的结果。

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<img src="graphs/alltickets.php" />
</body>
</html>

有什么想法吗?您还会为PHP推荐任何其他免费的图形库吗?

1 个答案:

答案 0 :(得分:0)

感谢Llama先生和VikingBlooded,我发现了我的问题。查看日志,我发现它无法引用我的db.inc文件。当我在将数据放在不同目录中的文件上之前测试数组时。在图表/ alltickets.php中,它引用了上面目录中的文件而没有../

所以我不得不改变的是

include '../db.inc';
这是一个愚蠢的错误。谢谢大家。