Get DataPointFill
public getDataPointFill ( integer $dataPointIndex ) : PhpOffice\PhpPresentation\Style\Fill | ||
$dataPointIndex | integer | Data point index. |
return | PhpOffice\PhpPresentation\Style\Fill |
public function testTypeBar() { $seriesData = array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 3, 'E' => 2); $oPhpPresentation = new PhpPresentation(); $oSlide = $oPhpPresentation->getActiveSlide(); $oShape = $oSlide->createChartShape(); $oShape->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80); $oBar = new Bar(); $oSeries = new Series('Downloads', $seriesData); $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_BLUE)); $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKBLUE)); $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKGREEN)); $oSeries->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKRED)); $oSeries->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color(Color::COLOR_DARKYELLOW)); $oBar->addSeries($oSeries); $oShape->getPlotArea()->setType($oBar); $oXMLDoc = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007'); $element = '/p:sld/p:cSld/p:spTree/p:graphicFrame/a:graphic/a:graphicData'; $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/slides/slide1.xml')); $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart'; $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename())); $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser'; $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename())); $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:dPt/c:spPr'; $this->assertTrue($oXMLDoc->elementExists($element, 'ppt/charts/' . $oShape->getIndexedFilename())); $element = '/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:tx/c:v'; $this->assertEquals($oSeries->getTitle(), $oXMLDoc->getElement($element, 'ppt/charts/' . $oShape->getIndexedFilename())->nodeValue); }
public function testDataPointFills() { $object = new Series(); $this->assertInternalType('array', $object->getDataPointFills()); $this->assertEmpty($object->getDataPointFills()); $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\Fill', $object->getDataPointFill(0)); }
public function testChartBarHorizontal() { $oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2)); $oSeries->setShowSeriesName(true); $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8')); $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFAB4744')); $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8AA64F')); $oBar = new Bar(); $oBar->setBarDirection(Bar::DIRECTION_HORIZONTAL); $oBar->addSeries($oSeries); $phpPresentation = new PhpPresentation(); $oSlide = $phpPresentation->getActiveSlide(); $oChart = $oSlide->createChartShape(); $oChart->getPlotArea()->setType($oBar); $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation'); $element = '/office:document-content/office:body/office:chart/chart:chart'; $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml')); $this->assertEquals('chart:bar', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml')); $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'stylePlotArea\']/style:chart-properties'; $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml')); $this->assertEquals('true', $pres->getElementAttribute($element, 'chart:vertical', 'Object 1/content.xml')); $this->assertFalse($pres->attributeElementExists($element, 'chart:three-dimensional', 'Object 1/content.xml')); $this->assertFalse($pres->attributeElementExists($element, 'chart:right-angled-axes', 'Object 1/content.xml')); }
public function testChartPie3D() { $oSeries = new Series('Series', array('Jan' => 1, 'Feb' => 5, 'Mar' => 2)); $oSeries->setShowSeriesName(true); $oSeries->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF4672A8')); $oSeries->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFAB4744')); $oSeries->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8AA64F')); $oPie3D = new Pie3D(); $oPie3D->addSeries($oSeries); $phpPresentation = new PhpPresentation(); $oSlide = $phpPresentation->getActiveSlide(); $oChart = $oSlide->createChartShape(); $oChart->getPlotArea()->setType($oPie3D); $pres = TestHelperDOCX::getDocument($phpPresentation, 'ODPresentation'); $element = '/office:document-content/office:body/office:chart/chart:chart'; $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml')); $this->assertEquals('chart:circle', $pres->getElementAttribute($element, 'chart:class', 'Object 1/content.xml')); $element = '/office:document-content/office:body/office:chart/chart:chart/chart:plot-area/chart:series/chart:data-point'; $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml')); $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisX\']/style:chart-properties'; $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml')); $this->assertEquals('true', $pres->getElementAttribute($element, 'chart:reverse-direction', 'Object 1/content.xml')); $element = '/office:document-content/office:automatic-styles/style:style[@style:name=\'styleAxisY\']/style:chart-properties'; $this->assertTrue($pres->elementExists($element, 'Object 1/content.xml')); $this->assertEquals('true', $pres->getElementAttribute($element, 'chart:reverse-direction', 'Object 1/content.xml')); }
/** * @param Chart $chart * @param Chart\Series $series * @throws \Exception */ private function writeSeries(Chart $chart, Chart\Series $series) { $chartType = $chart->getPlotArea()->getType(); $numRange = count($series->getValues()); // chart:series $this->xmlContent->startElement('chart:series'); $this->xmlContent->writeAttribute('chart:values-cell-range-address', 'table-local.$' . $this->rangeCol . '$2:.$' . $this->rangeCol . '$' . ($numRange + 1)); $this->xmlContent->writeAttribute('chart:label-cell-address', 'table-local.$' . $this->rangeCol . '$1'); if ($chartType instanceof Area) { $this->xmlContent->writeAttribute('chart:class', 'chart:area'); } elseif ($chartType instanceof AbstractTypeBar) { $this->xmlContent->writeAttribute('chart:class', 'chart:bar'); } elseif ($chartType instanceof Line) { $this->xmlContent->writeAttribute('chart:class', 'chart:line'); } elseif ($chartType instanceof AbstractTypePie) { $this->xmlContent->writeAttribute('chart:class', 'chart:circle'); } elseif ($chartType instanceof Scatter) { $this->xmlContent->writeAttribute('chart:class', 'chart:scatter'); } $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries' . $this->numSeries); if ($chartType instanceof Area || $chartType instanceof AbstractTypeBar || $chartType instanceof Line || $chartType instanceof Scatter) { $dataPointFills = $series->getDataPointFills(); if (empty($dataPointFills)) { $incRepeat = $numRange; } else { $inc = 0; $incRepeat = 0; $newFill = new Fill(); do { if ($series->getDataPointFill($inc)->getHashCode() != $newFill->getHashCode()) { // chart:data-point $this->xmlContent->startElement('chart:data-point'); $this->xmlContent->writeAttribute('chart:repeated', $incRepeat); // > chart:data-point $this->xmlContent->endElement(); $incRepeat = 0; // chart:data-point $this->xmlContent->startElement('chart:data-point'); $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries' . $this->numSeries . '_' . $inc); // > chart:data-point $this->xmlContent->endElement(); } $inc++; $incRepeat++; } while ($inc < $numRange); $incRepeat--; } // chart:data-point $this->xmlContent->startElement('chart:data-point'); $this->xmlContent->writeAttribute('chart:repeated', $incRepeat); // > chart:data-point $this->xmlContent->endElement(); } elseif ($chartType instanceof AbstractTypePie) { $count = count($series->getDataPointFills()); for ($inc = 0; $inc < $count; $inc++) { // chart:data-point $this->xmlContent->startElement('chart:data-point'); $this->xmlContent->writeAttribute('chart:style-name', 'styleSeries' . $this->numSeries . '_' . $inc); // > chart:data-point $this->xmlContent->endElement(); } } // > chart:series $this->xmlContent->endElement(); }
function fnSlide_Pie(PhpPresentation $objPHPPresentation) { global $oFill; global $oShadow; // Create templated slide echo EOL . date('H:i:s') . ' Create templated slide' . EOL; $currentSlide = createTemplatedSlide($objPHPPresentation); // Generate sample data for second chart echo date('H:i:s') . ' Generate sample data for chart' . EOL; $seriesData = array('Monday' => 18, 'Tuesday' => 23, 'Wednesday' => 14, 'Thursday' => 12, 'Friday' => 20, 'Saturday' => 8, 'Sunday' => 10); // Create a pie chart (that should be inserted in a shape) echo date('H:i:s') . ' Create a non-3D pie chart (that should be inserted in a chart shape)' . EOL; $pieChart = new Pie(); $pieChart->setExplosion(15); $series = new Series('Downloads', $seriesData); $series->getDataPointFill(0)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF7CB5EC')); $series->getDataPointFill(1)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF434348')); $series->getDataPointFill(2)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF90ED7D')); $series->getDataPointFill(3)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF7A35C')); $series->getDataPointFill(4)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FF8085E9')); $series->getDataPointFill(5)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFF15C80')); $series->getDataPointFill(6)->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE4D354')); $series->setShowPercentage(true); $series->setShowValue(false); $series->setShowSeriesName(false); $series->setShowCategoryName(true); $pieChart->addSeries($series); // Create a shape (chart) echo date('H:i:s') . ' Create a shape (chart)' . EOL; $shape = $currentSlide->createChartShape(); $shape->setName('PHPPresentation Daily Downloads')->setResizeProportional(false)->setHeight(550)->setWidth(700)->setOffsetX(120)->setOffsetY(80); $shape->setShadow($oShadow); $shape->setFill($oFill); $shape->getBorder()->setLineStyle(Border::LINE_SINGLE); $shape->getTitle()->setText('PHPPresentation Daily Downloads'); $shape->getTitle()->getFont()->setItalic(true); $shape->getPlotArea()->setType($pieChart); $shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE); $shape->getLegend()->getFont()->setItalic(true); }