Example #1
0
 public function testSeries()
 {
     $object = new Bar();
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart\\Type\\Bar', $object->addSeries(new Series()));
     $this->assertCount(1, $object->getSeries());
 }
Example #2
0
 /**
  * Write Type Bar
  *
  * @param  \PhpOffice\Common\XMLWriter       $objWriter    XML Writer
  * @param  \PhpOffice\PhpPresentation\Shape\Chart\Type\Bar $subject
  * @param  boolean                              $includeSheet
  * @throws \Exception
  */
 protected function writeTypeBar(XMLWriter $objWriter, Bar $subject, $includeSheet = false)
 {
     // c:bar3DChart
     $objWriter->startElement('c:barChart');
     // c:barDir
     $objWriter->startElement('c:barDir');
     $objWriter->writeAttribute('val', $subject->getBarDirection());
     $objWriter->endElement();
     // c:grouping
     $objWriter->startElement('c:grouping');
     $objWriter->writeAttribute('val', $subject->getBarGrouping());
     $objWriter->endElement();
     // Write series
     $seriesIndex = 0;
     foreach ($subject->getSeries() as $series) {
         // c:ser
         $objWriter->startElement('c:ser');
         // c:idx
         $objWriter->startElement('c:idx');
         $objWriter->writeAttribute('val', $seriesIndex);
         $objWriter->endElement();
         // c:order
         $objWriter->startElement('c:order');
         $objWriter->writeAttribute('val', $seriesIndex);
         $objWriter->endElement();
         // c:tx
         $objWriter->startElement('c:tx');
         $coords = $includeSheet ? 'Sheet1!$' . \PHPExcel_Cell::stringFromColumnIndex(1 + $seriesIndex) . '$1' : '';
         $this->writeSingleValueOrReference($objWriter, $includeSheet, $series->getTitle(), $coords);
         $objWriter->endElement();
         // Fills for points?
         $dataPointFills = $series->getDataPointFills();
         foreach ($dataPointFills as $key => $value) {
             // c:dPt
             $objWriter->startElement('c:dPt');
             // c:idx
             $this->writeElementWithValAttribute($objWriter, 'c:idx', $key);
             if ($value->getFillType() != Fill::FILL_NONE) {
                 // c:spPr
                 $objWriter->startElement('c:spPr');
                 // Write fill
                 $this->writeFill($objWriter, $value);
                 // ## c:spPr
                 $objWriter->endElement();
             }
             // ## c:dPt
             $objWriter->endElement();
         }
         // c:dLbls
         $objWriter->startElement('c:dLbls');
         if ($series->hasDlblNumFormat()) {
             //c:numFmt
             $objWriter->startElement('c:numFmt');
             $objWriter->writeAttribute('formatCode', $series->getDlblNumFormat());
             $objWriter->writeAttribute('sourceLinked', '0');
             $objWriter->endElement();
         }
         // c:txPr
         $objWriter->startElement('c:txPr');
         // a:bodyPr
         $objWriter->writeElement('a:bodyPr', null);
         // a:lstStyle
         $objWriter->writeElement('a:lstStyle', null);
         // a:p
         $objWriter->startElement('a:p');
         // a:pPr
         $objWriter->startElement('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');
         // Font - a:solidFill
         $objWriter->startElement('a:solidFill');
         $this->writeColor($objWriter, $series->getFont()->getColor());
         $objWriter->endElement();
         // Font - a:latin
         $objWriter->startElement('a:latin');
         $objWriter->writeAttribute('typeface', $series->getFont()->getName());
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         // a:endParaRPr
         $objWriter->startElement('a:endParaRPr');
         $objWriter->writeAttribute('lang', 'en-US');
         $objWriter->writeAttribute('dirty', '0');
         $objWriter->endElement();
         $objWriter->endElement();
         $objWriter->endElement();
         // c:showVal
         $this->writeElementWithValAttribute($objWriter, 'c:showVal', $series->hasShowValue() ? '1' : '0');
         // c:showCatName
         $this->writeElementWithValAttribute($objWriter, 'c:showCatName', $series->hasShowCategoryName() ? '1' : '0');
         // c:showSerName
         $this->writeElementWithValAttribute($objWriter, 'c:showSerName', $series->hasShowSeriesName() ? '1' : '0');
         // c:showPercent
         $this->writeElementWithValAttribute($objWriter, 'c:showPercent', $series->hasShowPercentage() ? '1' : '0');
         // c:showLeaderLines
         $this->writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->hasShowLeaderLines() ? '1' : '0');
         $objWriter->endElement();
         // c:spPr
         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:overlap
     $objWriter->startElement('c:overlap');
     if ($subject->getBarGrouping() == Bar::GROUPING_CLUSTERED) {
         $objWriter->writeAttribute('val', '0');
     } elseif ($subject->getBarGrouping() == Bar::GROUPING_STACKED || $subject->getBarGrouping() == Bar::GROUPING_PERCENTSTACKED) {
         $objWriter->writeAttribute('val', '100');
     }
     $objWriter->endElement();
     // c:gapWidth
     $objWriter->startElement('c:gapWidth');
     $objWriter->writeAttribute('val', '75');
     $objWriter->endElement();
     // c:shape
     $objWriter->startElement('c:shape');
     $objWriter->writeAttribute('val', 'box');
     $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();
     // c:axId
     $objWriter->startElement('c:axId');
     $objWriter->writeAttribute('val', '0');
     $objWriter->endElement();
     $objWriter->endElement();
 }