如何将PHPPresentation Chart系列轴显示为百分比而不是小数?

时间:2018-07-02 13:28:27

标签: php phppowerpoint phppresentation

在Powerpoint图表中,可以通过将格式选择为“数字”->“百分比”来将轴单位格式化为百分比。

我正在尝试在PHPPresentation图表中使用Y轴单位作为百分比(10%,20%.. 100%)来实现相同的目的,但是它将它们显示为值(0.1、0.2,...,1.0),而不进行格式化他们。本文使用的作者是Powerpoint 2007

$objWriter = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');

代码如下:

$seriesAoC = array(
'01/07/2015' => 0.2,
'01/08/2015' => 0.5,
'01/09/2015' => 0.8,
'01/10/2015' => 1.0
); //supposed to display plots at 20%, 50%, 80% and 100% on axis Y ???
$oFill = new Fill();
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFFFFFFF'));
$lineChart = new Line();

$series = new Series('AoC',  $seriesAoC);
$series->setShowSeriesName(false);
$series->setShowValue(false);
$series->setShowPercentage(true); //series axis label should be in percentage not decimals
$series->setShowLeaderLines(false);
$lineChart->addSeries($series);
$oGridLines = new Gridlines();
$oGridLines->getOutline()->setWidth(1);
$oGridLines->getOutline()->getFill()->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFD9D9D9'));

$shape = $slide->createChartShape();
$shape->setName('Completion Percentage')->setResizeProportional(false)->setHeight(300)->setWidth(550)->setOffsetX(50)->setOffsetY(120);
$shape->getPlotArea()->getAxisY()->setMajorGridlines($oGridLines);
$shape->getPlotArea()->getAxisY()->setMajorUnit(0.1);
$shape->getPlotArea()->getAxisY()->setMaxBounds(1.0);
$shape->getPlotArea()->getAxisY()->setMinBounds(0.0);
$shape->getPlotArea()->getAxisY()->setFormatCode('0%');
$shape->getPlotArea()->getAxisY()->setTitle("");
$shape->getPlotArea()->getAxisX()->setTitle("");
$shape->setFill($oFill);
$shape->getBorder()->setLineStyle(Border::LINE_SINGLE)->setLineWidth(0.5);
$shape->getTitle()->setText('Sample Title');
$shape->getTitle()->getFont()->setSize(10);
$shape->getTitle()->getAlignment()->setIndent(180);
$shape->getPlotArea()->setType($lineChart);    
$shape->getView3D()->setRotationX(30);
$shape->getView3D()->setPerspective(30);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_NONE);
$shape->getLegend()->setPosition(Legend::POSITION_TOP);
$shape->getLegend()->getFont()->setSize(8);

我们非常感谢您的帮助。

0 个答案:

没有答案