0

I am embarrassed, but I cannot seem to create a very simple php chart authored by: http://phpmaster.com/charting-with-pchart to work.

I verified the following: my Apache server is running PHP5, GD and Free Type support are enabled, and my directory paths are good (i.e. is_file was confirmed, all files are uploaded).

Here is the simple code:

 <?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);
 ?>

I've tried a few variations, but the above code looks, to me, to be sound. I am out of ideas. I really appreciate any help.

Thanks,

DM

hakre
  • 193,403
  • 52
  • 435
  • 836
user175328
  • 323
  • 3
  • 9
  • 23

2 Answers2

2

I finally figured out what was going on. First, I am using a newer pChart library than what was used in the simple example, so some of the syntax was incompatible.

Second, since I am calling my php page from an Ajax function, I had to render the chart as an image file .png, and then echo it within an HTML tag. Furthermore, I will have to unlink the .png file after it has been rendered, since I need to dynamically create these graphs.

user175328
  • 323
  • 3
  • 9
  • 23
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>';
    ?>
  • Welcome to StackOverflow. In addition to providing code, please edit your answer to include some text for explaining what you did and why it works. – buczek Apr 27 '16 at 16:06