2010-07-16 15 views
0

我使用PEAR中的一個名爲Image_Graph的PHP圖形庫來繪製由條形圖表示的數據點。圖像看起來很好,當有多個數據點,但只有當一個數據點,它看起來像這樣:當只有一個數據點時,PEAR Image_Graph不能正確繪圖

http://img594.imageshack.us/img594/2944/screenshot20100715at528s.png

有沒有其他人經歷過這個問題,PEAR的Image_Graph?有誰知道一個修復?我曾嘗試使用最新版本的Image_Graph以及SVN的副本。

這裏是我的圖形代碼:

public function drawGraph() { 
    $canvas =& Image_Canvas::factory('png', array('width' => 775, 'height' => 410, 'antialias' => true)); 
    $graph =& Image_Graph::factory('graph', $canvas); 

    $font =& $graph->addNew('ttf_font', 'lib/fonts/Helvetica_Neue.ttf'); 
    $font->setSize(12); 
    $graph->setFont($font); 

    $plotarea =& $graph->addNew('plotarea'); 
    $dataset =& Image_Graph::factory('dataset'); 

    foreach ($this->getResults() as $res) { 
    $dataset->addPoint($res['name'], $res['value']); 
    } 

    $plot =& $plotarea->addNew('bar', &$dataset); 

    $axisTitle = $this->_resultType->getName() . " (" . $this->_resultType->getUnits() . ")"; 
    $axisY =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y); 
    $axisY->setTitle($axisTitle, 'vertical'); 

    $filename = $this->_getFilename(); 
    return ($graph->done(array('tohtml' => 'true', 
     'filename' => GRAPHS_DIR . $filename))); 
} 

我想,這一定是有Image_Graph一個錯誤,但我不知道它可能是。

感謝您的幫助!

回答

0

不知道你是否還需要的答案:)

如果只有一個值Image_graph繪製Y軸上面的吧。

很高興知道$ this-> getResults()包含什麼,我想'name'是一個字符串,而且數組類似於array('name' => '33_Toshiba_pPVT_16GB', 'value' => 16.66)。在X軸上有一個字符串將產生一個類別X軸。 你可以填充$數據集後添加一個虛擬值來解決這個

if(count($this->getResults()) == 1) 
    $dataset->addPoint('', 0); 

這應該這樣做,但是,如果X軸是線性的(「名」是一個數字),然後強制最小和最大x軸值和條將很好地顯示。

$axisX =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X); 
$axisX->forceMinimum(1); 
$axisX->forceMaximum(3); 

另外,這裏是一個修復,如果你要編輯的Image_Graph代碼 http://pear.php.net/bugs/bug.php?id=7423

PS: 我只能讓你的例如通過與

更換

$plot =& $plotarea->addNew('bar', &$dataset); 

工作

$plot =& $plotarea->addNew('bar', array(&$dataset));