【问题标题】:Using pChart for the First Time第一次使用 pChart
【发布时间】:2012-08-05 07:25:15
【问题描述】:

我很尴尬,但我似乎无法创建由http://phpmaster.com/charting-with-pchart 创作的非常简单的 php 图表来工作。

我验证了以下几点:我的 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);
 ?>

我尝试了一些变体,但在我看来,上面的代码是正确的。我没主意了。非常感谢任何帮助。

谢谢,

私信

【问题讨论】:

  • 有什么错误吗?顺便说一句,不是&lt;php?,而是&lt;?php
  • (
  • php页面调用就好了。我可以回显“测试”;在页面上并呈现,但就是这样吗?
  • 请发布ajax请求代码。
  • 在您发布的文章中,他们说 provide a file location as an argument and Render() will save the image file to that location on your server .. 这样您就可以保存图像并通过 Ajax 仅返回该图像的位置。

标签: php header include pchart


【解决方案1】:

我终于弄清楚发生了什么。首先,我使用的是比简单示例中使用的更新的 pChart 库,因此某些语法不兼容。

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

【讨论】:

    【解决方案2】:
       <?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>';
        ?>
    

    【讨论】:

    • 欢迎来到 StackOverflow。除了提供代码之外,请编辑您的答案以包含一些文字来解释您所做的事情以及它为什么起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多