无法在php中的libchart库中打开错误

时间:2014-02-11 00:09:11

标签: php

我在项目中使用Libchart库来生成图表。我试图在libchart中执行示例,但我收到了以下错误。

  

imagepng(generated / demo1.png):无法打开流:没有这样的文件或   目录   C:\ xampp \ htdocs \ test \ fileupload \ libchart \ classes \ view \ plot \ Plot.php on   第284行

这是我的代码

include "libchart/classes/libchart.php";
$chart = new VerticalBarChart(500, 250);
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Jan 2005", 273));
$dataSet->addPoint(new Point("Feb 2005", 321));
$dataSet->addPoint(new Point("March 2005", 442));
$dataSet->addPoint(new Point("April 2005", 711));
$chart->setDataSet($dataSet);
$chart->setTitle("Monthly usage for www.example.com");
$chart->render("generated/demo1.png");

当我将最后一行代码更改为$chart->render();时,它会在我的浏览器中打开二进制格式。 有人可以帮我解决这个错误吗?

2 个答案:

答案 0 :(得分:0)

this is my complete code
<?php
include "libchart/classes/libchart.php";

class fileupload
{

  var $htmlID_type = "type";
  var $type_uploadfile = 0;
  var $type_generategraphs = 1;
  var $content_html = "";


    function __construct()
    {
        $this->__switch();
        $this->__print();
    }

  function __switch()
 {


    enter code here
        $this->param_type = $this->getParamType();

        switch ($this->param_type)
        {`enter code here`
            case $this->type_uploadfile :
                $this->selectFileUplaod ();
                break;

            case $this->type_generategraphs :
                $this->generateGraphs();
                break;

        }

    }

    function __print()
    {
        print <<<HEREDOC

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns="http://www.w3.org/1999/xhtml">
                    <head>
                    <style>
                    body{
                      margin-left:20%;
                      margin-right:20%;
                      margin-top:50px;
                     }
                     table, td, th
                     {
                         border:1px solid black;
                      }
                     th
                       {
                          background-color:#00BFFF;
                          color:white;
                           }
                     </style>
                    </head>
                    <body>
                        {$this->content_html}
                    </body>

                    </html>



HEREDOC;
    }

  function getParamType()
    {
        if (isset ( $_GET [$this->htmlID_type] ))
        {
            return $_GET [$this->htmlID_type];
        } 
        else
            return $this->type_uploadfile;
    }



    function selectFileUplaod()
    {

       $con=mysqli_connect("localhost","root","","test");
      // Check connection
        if (mysqli_connect_errno())
        {
               echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }

        $result = mysqli_query($con,"SELECT 
              income_id,
              month,
              paint_cost,
              parts_cost,
              repair_cost,
              excess_Suspense,
              sublet,
              remove_refit_cost
              FROM income");
        echo "<h3>Bundamba Income</h3>";
        echo "<table>
         <tr>
         <th>Paint</th>
         <th>Parts</th>
         <th>Remove Refit Cost</th>
         <th>Repair</th>
         <th>Excess Suspense</th>
         <th>Sublet</th>
        </tr>";

      while($row = mysqli_fetch_array($result))
      {
       echo "<tr>";
       echo "<td width=100>" . $row['paint_cost'] . "</td>";
       echo "<td width=100>" . $row['parts_cost'] . "</td>";
       echo "<td width=100>" . $row['remove_refit_cost'] . "</td>";
       echo "<td width=100>" . $row['repair_cost'] . "</td>";
        echo "<td width=100>" . $row['excess_Suspense'] . "</td>";
        echo "<td width=100>" . $row['sublet'] . "</td>";
       echo "</tr>";
      }
      echo "</table>";
      echo "<br>";
      $result1 = mysqli_query($con,"SELECT  
              cost_of_saleID ,  paint_liquid ,  
              paint_consumables,  
              workshop_consumables,
              parts_purchased,
              wages_paintshop,
              wages_workshop,
              suplier_discount,
              sublet_cost 
              FROM  cost_of_sale 
                LIMIT 0 , 30");
        echo "<h3>Bundamba cost of sale</h3>";
        echo "<table>
         <tr>
         <th>Paint Consumables</th>
         <th>Paint Liquid</th>
          <th>Parts Purchased</th>
          <th>Workshop Consumables</th>
          <th>Wages - Paintshop</th>
          <th>Wages - Workshop</th>
          <th>Supplier Discounts</th>
          <th>Sublets Costs</th>
        </tr>";

      while($row = mysqli_fetch_array($result1))
      {
       echo "<tr>";
       echo "<td>" . $row['paint_consumables'] . "</td>";
       echo "<td>" . $row['paint_liquid'] . "</td>";
       echo "<td>" . $row['parts_purchased'] . "</td>";
       echo "<td>" . $row['workshop_consumables'] . "</td>";
       echo "<td>" . $row['wages_paintshop'] . "</td>";
       echo "<td>" . $row['wages_workshop'] . "</td>";
       echo "<td>" . $row['suplier_discount'] . "</td>";
       echo "<td>" . $row['sublet_cost'] . "</td>";
       echo "</tr>";
      }
      echo "</table>";
    $this->content_html = <<<End_Of_String

            <FORM action="uploadFile.php?{$this->htmlID_type}={$this->type_generategraphs}" method="POST" />
             <input type="submit" value="Income vs Cost" style="margin-top:20px">
             <input type="submit" value="Income vs Cost Ratio" style="margin-top:20px">
            </FORM> 


End_Of_String;


   // mysqli_close($con);


}   

    function generateGraphs()
    {
        echo  getcwd();
        print "rrrrr";
       header("Content-type:image/png");    

       $chart = new VerticalBarChart(500, 250);

       $dataSet = new XYDataSet();
       $dataSet->addPoint(new Point("Jan 2005", 273));
       $dataSet->addPoint(new Point("Feb 2005", 321));
       $dataSet->addPoint(new Point("March 2005", 442));
       $dataSet->addPoint(new Point("April 2005", 711));
       $chart->setDataSet($dataSet);
       $chart->setTitle("Monthly usage for www.example.com");


        $chart->render("demo/generated/demo1.png");
        readfile("demo/generated/demo1.png");


       // $im = imagecreatefrompng("demo/generated/demo1.png");
       // header('Content-Type: image/png');
       //imagepng($im);
       //imagedestroy($im);

    }   


}


$obj = new fileupload();
?>

答案 1 :(得分:0)

我在尝试使用LibChart库绘制饼图时遇到了同样的错误。问题是您不会在当前文件夹中创建名为“generated”的文件夹..但是为图像指定的名称是生成/ demo1.png,表示生成的文件夹包含文件“demo1.png”。所以,只需给出'demo1.png'而不是'generated / demo1.png'并尝试运行代码片段..我刚才得​​到了输出!!