2014-12-04 27 views
0

我有2個陣列的條形圖。 $pm$estimate如何同步圖表導演中的2個y軸

我計算$percent = ($estimate/$pm) * 100有一個百分比的數組來創建我的折線圖的值。

現在的問題是如何在條形圖和折線圖中同步我的2個y軸。

這裏是我的代碼

$transmonth = array(1, 2, 3); 
$estimate = array(80, 50, 40); 
$pm = array(10, 5, 8); 

foreach($estimate as $k => $v){ 
    $percent[$k] = ($pm[$k]/$v) * 100; 
} 

$data = $percent; 
$data1 = $estimate; 
$data2 = $pm; 
$labels = $transmonth; 

$c = new XYChart(780, 400, -1,1); 
$c->addTitle("Mini-PM Hit Rate"); 

# Set the plotarea at (80, 40) and of 650, 300 pixels in size. Use alternating light 
# grey (f8f8f8)/white (ffffff) background. Set border to transparent and use grey 
# (CCCCCC) dotted lines as horizontal and vertical grid lines 

$c->setPlotArea(80, 80, 650, 250, 0xffffff, 0xf8f8f8,Transparent, $c->dashLineColor(0xcccccc, Dotline), $c->dashLineColor(0xcccccc, Dotline)); 

$legendObj = $c->addLegend(70, 50, false, "arial.ttf", 10); 
$legendObj->setBackground(Transparent); 

$lineLayer = $c->addLineLayer2(); 

$lineLayerObj = $lineLayer->addDataSet($data, 0x009966, "Hit Rate Percentage"); 
$lineLayerObj->setDataSymbol(CircleShape, 9, 0xff9966, 0x009966); 
$lineLayerObj->setDataLabelFormat("{value|1}"); 
$lineLayerObj->setDataLabelStyle("arialbd.ttf", 8); 

$lineLayer->setLineWidth(2); 
$lineLayer->setUseYAxis2(); 
$c->yAxis2->setLinearScale(0, 120, 10); 

$layer = $c->addBarLayer2(Side); 
$layer->addDataSet($data1, 0x10b4f1, "Estimated PM"); 
$layer->addDataSet($data2, 0x7B3BA3, "Actual PM"); 
$layer->setBorderColor(Transparent); 
$layer->setBarGap(0.2, TouchBar); 


$c->xAxis->setLabels($labels); 
$c->xAxis->setTickOffset(0.5); 

$c->xAxis->setTitle("Period"); 
$c->yAxis->setTitle("Total Handlers"); 
$c->yAxis2->setTitle("Hit Rate Percentage (%)"); 

header("Content-type: image/png"); 
print($c->makeChart2(PNG)); 

請幫助。

回答

0

根據你的代碼,百分比可以遠高於100%。但是,代碼中有一行將yAxis2配置爲僅從0到120。所以百分比數據可能會溢出軸範圍。如果刪除該行代碼並讓ChartDirector 自動確定yAxis2的y軸刻度,則該刻度將使整個 行落入該圖表內。

+0

多數民衆贊成我的問題其實...........兄弟如何我可以同步我的yaxis2 yaxis .....我的意思是如何設置我的yaxis2依賴yaxis和自動調整它.. ...你能幫我做到嗎?????????? – elvis 2014-12-08 00:43:58