2011-04-27 49 views
0

我正在使用pchartzend框架應用程序創建圖表。我的問題是,我不能讓應用程序顯示圖表,因爲每次獲取上述命名錯誤。我已經看過與這個問題有關的各種解決方案,但我仍然無法工作。有什麼在這裏失蹤?請參考代碼pchart zend框架錯誤「圖像無法顯示,因爲它包含錯誤」

{

require 'pChart2.1.1/pChart2.1.1/class/pData.class.php'; 
    require 'pChart2.1.1/pChart2.1.1/class/pDraw.class.php'; 
    require 'pChart2.1.1/pChart2.1.1/class/pImage.class.php'; 
    require 'pChart2.1.1/pChart2.1.1/class/pPie.class.php'; 


    // action body 
    $users = new Application_Model_DbTable_Users(); 
    $users = $users->listAll(); 

    $id=$this->_getParam('id'); 

    if($id) 
    { 
      $this->_helper->viewRenderer->setNoRender(true); 
      $this->_helper->layout()->disableLayout(); 
      $response=$this->getResponse(); 
      $response->clearBody('top_menu'); 
      $response->clearAllHeaders(); 

    if ($id == 'pdf') { 
        } 


     //request is a chart 

     if($id=='chart') 
     { 
      ob_start(); 

      $departments=new Application_Model_DbTable_Departments(); 

      $departments=$departments->fetchAll(); 

      $departments->toArray(); 

      $department_id=""; 
      $department_name=""; 

      foreach ($departments as $departments) { 
       $department_id[]=$departments['department_id']; 
       $department_name[]=$departments['department_name']; 



       /* pData object creation */ 
       $MyData = new pData(); 
       /* Data definition */ 
       $MyData->addPoints(array(20, 30, 25, 10), "Value"); 
        /* Labels definition */ 
       $MyData->addPoints($department_name, "Legend"); 
       $MyData->setAbscissa("Legend"); 
       /* Create the pChart object */ 
       $myPicture = new pImage(500, 500, $MyData); 
       /* Draw a gradient background */ 
       $myPicture->drawGradientArea(0, 0, 500, 500, 
       DIRECTION_HORIZONTAL, 
       array("StartR" => 220, "StartG" => 220, "StartB" => 220, 
       "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 100)); 
       /* Add a border to the picture */ 
       $myPicture->drawRectangle(0, 0, 400, 400, 
       array("R" => 0, "G" => 0, "B" => 0)); 
       /* Create the pPie object */ 
       $PieChart = new pPie($myPicture, $MyData); 
       /* Enable shadow computing */ 
       $myPicture->setShadow(FALSE); 
       /* Set the default font properties */ 
       $myPicture->setFontProperties(
       array(
       "FontName" => "pChart2.1.1/pChart2.1.1/fonts/Forgotte.ttf", 
       "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); 
       /* Draw a splitted pie chart */ 
       $PieChart->draw3DPie(200, 150, 
       array("Radius" => 100, "DrawLabels" => TRUE, 
       "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE)); 
       /* Render the picture (choose the best way) */ 

       header ("Content-type: image/png"); 
       $myPicture->Stroke("pie.png"); 

       exit; 


      } 


     } 

} 

回答

0

這裏幾乎肯定是在輸出之前或圖像內容之後。最簡單的做法是暫時將您的header("Content-type: image/png");行註釋掉,然後在瀏覽器中查看圖表圖像。你會看到一大堆二進制數據(圖像) - 在它看起來不合適的位置之前或之後尋找任何東西(例如,PHP錯誤消息,一些HTML,可能是空白)。

+0

我還沒有設法清除,我檢查了我的二進制圖像,似乎沒關係,你認爲require語句可能是這裏的問題嗎? – ngunjirimacharia 2011-04-27 16:40:54

+1

可能的話,試着在你要求的每個課程結束時(如果他們有一個的話)去除結束?>。這可以防止任何空白後導致問題。 – 2011-04-28 09:23:52

0

經過很多天,我終於得到了我首先犯的錯誤,在我的引導程序中有一個空行,並且是我的控制器的結尾,我還將我的pchart放在公用文件夾中,因爲它具有字體,最後我意識到我應該在最上面設置響應標題。

謝謝大家!

相關問題