我很尴尬,但我似乎不能创建一个非常简单的php图表作者:http://phpmaster.com/charting-with-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
发布于 2012-08-05 17:23:38
我终于弄明白是怎么回事了。首先,我使用的pChart库比简单示例中使用的库更新,因此一些语法是不兼容的。
其次,由于我是从Ajax函数调用我的php页面,所以我必须将图表呈现为图像文件.png,然后在HTML标记中回显它。此外,由于我需要动态创建这些图形,因此在渲染.png文件后,我必须取消它的链接。
发布于 2016-04-27 23:44:19
<?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>';
?>https://stackoverflow.com/questions/11814674
复制相似问题