2012-08-05 63 views
0

我很尴尬,但我似乎无法创建一个非常简单的php图表,作者:http://phpmaster.com/charting-with-pchart工作。第一次使用pChart

我验证了以下内容:我的Apache服务器运行PHP5,GD和Free Type支持已启用,并且我的目录路径很好(即is_file已被确认,所有文件都已上传)。

下面是简单的代码:

<?php 
session_start(); 
require_once('library/class/pData_class.php');  
require_once('library/class/pChart_class.php'); 

$myDataset = array(0, 1, 2, 3, 4, 5, 7, 9); 
$myData = new pData(); 
$myData->addPoints($myDataset); 
$myImage = new pImage(500, 300, $myData); 

$myImage->setFontProperties(array("FontName" => PCHART_PATH . "library/fonts/GeosansLight.ttf", "FontSize" => 15)); 
$myImage->setGraphArea(25, 25, 475, 275); 
$myImage->drawScale(); 
$myImage->drawBarChart(); 
header("Content-Type: image/png"); 
$myImage->Render(null); 
?> 

我已经尝试了一些变化,但上面的代码看起来,对我来说,是合理的。我没有想法。我非常感谢任何帮助。

感谢,

DM

+0

任何错误或什么? btw它不是' thinklinux 2012-08-05 07:39:06

+0

user175328 2012-08-05 08:35:33

+0

这个php页面调用很好。我可以回显'测试';在页面上呈现,但是那是它? – user175328 2012-08-05 08:39:24

回答

2

我终于想通了事情的原委。首先,我使用的是比简单示例中使用的更新的pChart库,因此某些语法不兼容。

其次,由于我从Ajax函数调用我的php页面,因此必须将图表渲染为图像文件.png,然后在HTML标记中回显它。此外,我将不得不在渲染后解除.png文件的链接,因为我需要动态创建这些图。

0
<?php 
    session_start(); 
    require_once "/class/pDraw.class.php"; 
    require_once "/class/pImage.class.php"; 
    require_once "/class/pData.class.php"; 


    $myDataset = array($one, $two, $three, $four, $five); 

    $myData = new pData(); 
    $myData->addPoints($myDataset); 

    $myImage = new pImage(500, 300, $myData); 

    $myImage->setFontProperties(array(
       "FontName" => "/fonts/GeosansLight.ttf", 
       "FontSize" => 15)); 

    $myImage->setGraphArea(25,25, 475,275); 
    $myImage->drawScale(); 
    $myImage->drawBarChart(); 

    //header(""); 
    $myImage->Render("image.png"); 

    echo '<p><img src="yourpath/image.png"></p>'; 
    ?> 
+0

欢迎来到StackOverflow。除了提供代码之外,请编辑您的答案以包含一些文字,用于解释您所做的事情以及它的工作原理。 – buczek 2016-04-27 16:06:27