Example #1
0
 public function testSeries()
 {
     $object = new Area();
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Area', $object->addSeries(new Series()));
     $this->assertCount(1, $object->getSeries());
 }
Example #2
0
 /**
  * Write Type Area
  *
  * @param  \PhpOffice\Common\XMLWriter      $objWriter    XML Writer
  * @param  \PhpOffice\PhpPresentation\Shape\Chart\Type\Area $subject
  * @param  boolean                             $includeSheet
  * @throws \Exception
  */
 protected function writeTypeArea(XMLWriter $objWriter, Area $subject, $includeSheet = false)
 {
     // c:lineChart
     $objWriter->startElement('c:areaChart');
     // c:grouping
     $objWriter->startElement('c:grouping');
     $objWriter->writeAttribute('val', 'standard');
     $objWriter->endElement();
     // Write series
     $seriesIndex = 0;
     foreach ($subject->getSeries() as $series) {
         // c:ser
         $objWriter->startElement('c:ser');
         // c:ser > c:idx
         $objWriter->startElement('c:idx');
         $objWriter->writeAttribute('val', $seriesIndex);
         $objWriter->endElement();
         // c:ser > c:order
         $objWriter->startElement('c:order');
         $objWriter->writeAttribute('val', $seriesIndex);
         $objWriter->endElement();
         // c:ser > c:tx
         $objWriter->startElement('c:tx');
         $coords = $includeSheet ? 'Sheet1!$' . \PHPExcel_Cell::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '';
         $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
         $objWriter->endElement();
         // c:ser > c:dLbls
         $objWriter->startElement('c:dLbls');
         // c:ser > c:dLbls > c:txPr
         $objWriter->startElement('c:txPr');
         // c:ser > c:dLbls > c:txPr > a:bodyPr
         $objWriter->writeElement('a:bodyPr', null);
         // c:ser > c:dLbls > c:txPr > a:lstStyle
         $objWriter->writeElement('a:lstStyle', null);
         // c:ser > c:dLbls > c:txPr > a:p
         $objWriter->startElement('a:p');
         // c:ser > c:dLbls > c:txPr > a:p > a:pPr
         $objWriter->startElement('a:pPr');
         // c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr
         $objWriter->startElement('a:defRPr');
         $objWriter->writeAttribute('b', $series->getFont()->isBold() ? 'true' : 'false');
         $objWriter->writeAttribute('i', $series->getFont()->isItalic() ? 'true' : 'false');
         $objWriter->writeAttribute('strike', $series->getFont()->isStrikethrough() ? 'sngStrike' : 'noStrike');
         $objWriter->writeAttribute('sz', $series->getFont()->getSize() * 100);
         $objWriter->writeAttribute('u', $series->getFont()->getUnderline());
         $objWriter->writeAttributeIf($series->getFont()->isSuperScript(), 'baseline', '30000');
         $objWriter->writeAttributeIf($series->getFont()->isSubScript(), 'baseline', '-25000');
         // c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr > a:solidFill
         $objWriter->startElement('a:solidFill');
         $this->writeColor($objWriter, $series->getFont()->getColor());
         // c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr > ## a:solidFill
         $objWriter->endElement();
         // c:ser > c:dLbls > c:txPr > a:p > a:pPr > a:defRPr > a:latin
         $objWriter->startElement('a:latin');
         $objWriter->writeAttribute('typeface', $series->getFont()->getName());
         $objWriter->endElement();
         // c:ser > c:dLbls > c:txPr > a:p > a:pPr > ##a:defRPr
         $objWriter->endElement();
         // c:ser > c:dLbls > c:txPr > a:p > ##a:pPr
         $objWriter->endElement();
         // c:ser > c:dLbls > c:txPr > a:p > a:endParaRPr
         $objWriter->startElement('a:endParaRPr');
         $objWriter->writeAttribute('lang', 'en-US');
         $objWriter->writeAttribute('dirty', '0');
         $objWriter->endElement();
         // c:ser > c:dLbls > c:txPr > ##a:p
         $objWriter->endElement();
         // c:ser > c:dLbls > ##c:txPr
         $objWriter->endElement();
         // c:ser > c:dLbls > c:dLblPos
         $this->writeElementWithValAttribute($objWriter, 'c:dLblPos', $series->getLabelPosition());
         // c:ser > c:dLbls > c:showVal
         $this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0');
         // c:ser > c:dLbls > c:showCatName
         $this->writeElementWithValAttribute($objWriter, 'c:showCatName', $series->hasShowCategoryName() ? '1' : '0');
         // c:ser > c:dLbls > c:showSerName
         $this->writeElementWithValAttribute($objWriter, 'c:showSerName', $series->hasShowSeriesName() ? '1' : '0');
         // c:ser > c:dLbls > c:showPercent
         $this->writeElementWithValAttribute($objWriter, 'c:showPercent', $series->hasShowPercentage() ? '1' : '0');
         // c:ser > c:dLbls > c:showLeaderLines
         $this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
         // c:ser > ##c:dLbls
         $objWriter->endElement();
         if ($series->getFill()->getFillType() != Fill::FILL_NONE) {
             // c:spPr
             $objWriter->startElement('c:spPr');
             // Write fill
             $this->writeFill($objWriter, $series->getFill());
             // ## c:spPr
             $objWriter->endElement();
         }
         // Write X axis data
         $axisXData = array_keys($series->getValues());
         // c:cat
         $objWriter->startElement('c:cat');
         $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisXData, 'Sheet1!$A$2:$A$' . (1 + count($axisXData)));
         $objWriter->endElement();
         // Write Y axis data
         $axisYData = array_values($series->getValues());
         // c:val
         $objWriter->startElement('c:val');
         $coords = $includeSheet ? 'Sheet1!$' . \PHPExcel_Cell::stringFromColumnIndex($seriesIndex + 1) . '$2:$' . \PHPExcel_Cell::stringFromColumnIndex($seriesIndex + 1) . '$' . (1 + count($axisYData)) : '';
         $this->writeMultipleValuesOrReference($objWriter, $includeSheet, $axisYData, $coords);
         $objWriter->endElement();
         $objWriter->endElement();
         ++$seriesIndex;
     }
     // c:marker
     $objWriter->startElement('c:marker');
     $objWriter->writeAttribute('val', '1');
     $objWriter->endElement();
     // c:smooth
     $objWriter->startElement('c:smooth');
     $objWriter->writeAttribute('val', '0');
     $objWriter->endElement();
     // c:axId
     $objWriter->startElement('c:axId');
     $objWriter->writeAttribute('val', '52743552');
     $objWriter->endElement();
     // c:axId
     $objWriter->startElement('c:axId');
     $objWriter->writeAttribute('val', '52749440');
     $objWriter->endElement();
     $objWriter->endElement();
 }