如何在Chart director中同步2个y轴

时间:2014-12-04 01:23:25

标签: php drupal-6 chart-director

我有2个条形图数组。 $pm$estimate

我正在计算$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));

请帮忙。

1 个答案:

答案 0 :(得分:0)

根据您的代码,百分比可能远高于100%。但是,代码中有一行将yAxis2配置为仅从0到120。因此,百分比数据可能会溢出轴范围。如果删除该行代码并让ChartDirector 自动确定yAxis2的y轴刻度,刻度将是整个 线将落在图表中。