Skip to content

Commit

Permalink
#76 : Sample for Line Chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Dec 31, 2014
1 parent aae558f commit 55a4cfe
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 52 deletions.
45 changes: 4 additions & 41 deletions samples/Sample_07_Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);

// Create templated slide
echo date('H:i:s') . ' Create templated slide'.EOL;
echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPowerPoint);

// Generate sample data for first chart
Expand Down Expand Up @@ -89,7 +89,7 @@


// Create templated slide
echo date('H:i:s') . ' Create templated slide'.EOL;
echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPowerPoint);

// Create a bar chart (that should be inserted in a shape)
Expand Down Expand Up @@ -122,7 +122,7 @@
$shape->getLegend()->getFont()->setItalic(true);

// Create templated slide
echo date('H:i:s') . ' Create templated slide'.EOL;
echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPowerPoint);

// Generate sample data for second chart
Expand Down Expand Up @@ -165,44 +165,7 @@
$shape->getLegend()->getFont()->setItalic(true);

// Create templated slide
echo date('H:i:s') . ' Create templated slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPowerPoint); // local function

// Generate sample data for third chart
echo date('H:i:s') . ' Generate sample data for third chart'.EOL;
$seriesData = array('Monday' => 12, 'Tuesday' => 15, 'Wednesday' => 13, 'Thursday' => 17, 'Friday' => 14, 'Saturday' => 9, 'Sunday' => 7);

// Create a line chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)'.EOL;
$lineChart = new Line();
$series = new Series('Downloads', $seriesData);
$series->setShowSeriesName(true);
$series->setShowValue(false);
$lineChart->addSeries($series);

// Create a shape (chart)
echo date('H:i:s') . ' Create a shape (chart)'.EOL;
$shape = $currentSlide->createChartShape();
$shape->setName('PHPPowerPoint 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('PHPPowerPoint Daily Downloads');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getPlotArea()->setType($lineChart);
$shape->getView3D()->setRotationX(30);
$shape->getView3D()->setPerspective(30);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);


// Create templated slide
echo date('H:i:s') . ' Create templated slide'.EOL;
echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPowerPoint); // local function

// Generate sample data for fourth chart
Expand Down
102 changes: 102 additions & 0 deletions samples/Sample_07_Chart_Line.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

include_once 'Sample_Header.php';

use PhpOffice\PhpPowerpoint\PhpPowerpoint;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Bar3D;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Line;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Pie3D;
use PhpOffice\PhpPowerpoint\Shape\Chart\Type\Scatter;
use PhpOffice\PhpPowerpoint\Shape\Chart\Series;
use PhpOffice\PhpPowerpoint\Style\Alignment;
use PhpOffice\PhpPowerpoint\Style\Border;
use PhpOffice\PhpPowerpoint\Style\Color;
use PhpOffice\PhpPowerpoint\Style\Fill;
use PhpOffice\PhpPowerpoint\Style\Shadow;

// Create new PHPPowerPoint object
echo date('H:i:s') . ' Create new PHPPowerPoint object'.EOL;
$objPHPPowerPoint = new PhpPowerpoint();

// Set properties
echo date('H:i:s') . ' Set properties'.EOL;
$objPHPPowerPoint->getProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPowerPoint Team')
->setTitle('Sample 07 Title')
->setSubject('Sample 07 Subject')
->setDescription('Sample 07 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');

// Remove first slide
echo date('H:i:s') . ' Remove first slide'.EOL;
$objPHPPowerPoint->removeSlideByIndex(0);

// Set Style
$oFill = new Fill();
$oFill->setFillType(Fill::FILL_SOLID)->setStartColor(new Color('FFE06B20'));

$oShadow = new Shadow();
$oShadow->setVisible(true)->setDirection(45)->setDistance(10);

// Generate sample data for chart
echo date('H:i:s') . ' Generate sample data for chart'.EOL;
$seriesData = array('Monday' => 12, 'Tuesday' => 15, 'Wednesday' => 13, 'Thursday' => 17, 'Friday' => 14, 'Saturday' => 9, 'Sunday' => 7);

// Create templated slide
echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPowerPoint);

// Create a line chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)'.EOL;
$lineChart = new Line();
$series = new Series('Downloads', $seriesData);
$series->setShowSeriesName(true);
$series->setShowValue(true);
$lineChart->addSeries($series);

// Create a shape (chart)
echo date('H:i:s') . ' Create a shape (chart)'.EOL;
$shape = $currentSlide->createChartShape();
$shape->setName('PHPPowerPoint 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('PHPPowerPoint Daily Downloads');
$shape->getTitle()->getFont()->setItalic(true);
$shape->getPlotArea()->setType($lineChart);
$shape->getView3D()->setRotationX(30);
$shape->getView3D()->setPerspective(30);
$shape->getLegend()->getBorder()->setLineStyle(Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);

// Create templated slide
echo EOL.date('H:i:s') . ' Create templated slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPowerPoint);

// Create a line chart (that should be inserted in a shape)
echo date('H:i:s') . ' Create a line chart (that should be inserted in a chart shape)'.EOL;
$lineChart1 = clone $lineChart;

// Create a shape (chart)
echo date('H:i:s') . ' Create a shape (chart)'.EOL;
echo date('H:i:s') . ' Differences with previous : Values on right axis and Legend hidden'.EOL;
$shape1 = clone $shape;
$shape1->getLegend()->setVisible(false);
$shape1->setName('PHPPowerPoint Weekly Downloads');
$shape1->getTitle()->setText('PHPPowerPoint Weekly Downloads');
$shape1->getPlotArea()->setType($lineChart1);
$shape1->getPlotArea()->getAxisY()->setFormatCode('#,##0');
$currentSlide->addShape($shape1);

// Save file
echo EOL.write($objPHPPowerPoint, basename(__FILE__, '.php'), $writers);

if (!CLI) {
include_once 'Sample_Footer.php';
}
8 changes: 8 additions & 0 deletions src/PhpPowerpoint/AbstractShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ public function __construct()

$this->border->setLineStyle(Style\Border::LINE_NONE);
}

public function __clone() {
$this->container = null;
$this->fill = clone $this->fill;
$this->border = clone $this->border;
$this->shadow = clone $this->shadow;
}

/**
* Get Container, Slide or Group
Expand Down Expand Up @@ -159,6 +166,7 @@ public function setContainer(ShapeContainerInterface $pValue = null, $pOverrideO
$this->container = null;
break;
}
$iterator->next();
}

// Set new \PhpOffice\PhpPowerpoint\Slide
Expand Down
1 change: 1 addition & 0 deletions src/PhpPowerpoint/HashTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function add(ComparableInterface $pSource)
{
// Determine hashcode
$hashIndex = $pSource->getHashIndex();

if (is_null($hashIndex)) {
$hashCode = $pSource->getHashCode();
} elseif (isset($this->keyMap[$hashIndex])) {
Expand Down
8 changes: 8 additions & 0 deletions src/PhpPowerpoint/Shape/AbstractDrawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public function __construct()
// Initialize parent
parent::__construct();
}

public function __clone()
{
parent::__clone();

self::$imageCounter++;
$this->imageIndex = self::$imageCounter;
}

/**
* Get image index
Expand Down
9 changes: 9 additions & 0 deletions src/PhpPowerpoint/Shape/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public function __construct()
// Initialize parent
parent::__construct();
}

public function __clone() {
parent::__clone();

$this->title = clone $this->title;
$this->legend = clone $this->legend;
$this->plotArea = clone $this->plotArea;
$this->view3D = clone $this->view3D;
}

/**
* Get Title
Expand Down
5 changes: 5 additions & 0 deletions src/PhpPowerpoint/Shape/Chart/PlotArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public function __construct()
$this->axisX = new Axis();
$this->axisY = new Axis();
}

public function __clone() {
$this->axisX = clone $this->axisX;
$this->axisY = clone $this->axisY;
}

/**
* Get type
Expand Down
14 changes: 5 additions & 9 deletions src/PhpPowerpoint/Writer/PowerPoint2007/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, ShapeC
$objWriter->writeAttribute('val', 'minMax');
$objWriter->endElement();

// ## c:scaling
$objWriter->endElement();

// c:axPos
Expand All @@ -649,10 +650,6 @@ protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, ShapeC
$objWriter->writeAttribute('sourceLinked', '0');
$objWriter->endElement();

// c:majorGridlines
//$objWriter->startElement('c:majorGridlines');
//$objWriter->endElement();

// c:majorTickMark
$objWriter->startElement('c:majorTickMark');
$objWriter->writeAttribute('val', 'none');
Expand Down Expand Up @@ -681,6 +678,7 @@ protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, ShapeC
// a:defRPr
$objWriter->writeElement('a:defRPr', null);

// ## a:pPr
$objWriter->endElement();

// a:r
Expand All @@ -695,6 +693,7 @@ protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, ShapeC
// a:t
$objWriter->writeElement('a:t', $subject->getAxisY()->getTitle());

// ## a:r
$objWriter->endElement();

// a:endParaRPr
Expand All @@ -703,8 +702,10 @@ protected function writePlotArea(XMLWriter $objWriter, PlotArea $subject, ShapeC
$objWriter->writeAttribute('dirty', '0');
$objWriter->endElement();

// ## a:p
$objWriter->endElement();

// ## c:txPr
$objWriter->endElement();

// c:crossAx
Expand Down Expand Up @@ -1290,11 +1291,6 @@ protected function writeTypeLine(XMLWriter $objWriter, Line $subject, $includeSh
$objWriter->writeAttribute('val', 'standard');
$objWriter->endElement();

// c:varyColors
$objWriter->startElement('c:varyColors');
$objWriter->writeAttribute('val', '0');
$objWriter->endElement();

// Write series
$seriesIndex = 0;
foreach ($subject->getData() as $series) {
Expand Down
2 changes: 0 additions & 2 deletions src/PhpPowerpoint/Writer/PowerPoint2007/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public function writePresentation(PHPPowerPoint $pPHPPowerPoint = null)

// p:sldSz
$objWriter->startElement('p:sldSz');
//$objWriter->writeAttribute('cx', '9144000');
//$objWriter->writeAttribute('cy', '6858000');
$objWriter->writeAttribute('cx', $pPHPPowerPoint->getLayout()->getCX());
$objWriter->writeAttribute('cy', $pPHPPowerPoint->getLayout()->getCY());
if ($pPHPPowerPoint->getLayout()->getDocumentLayout() != DocumentLayout::LAYOUT_CUSTOM) {
Expand Down

0 comments on commit 55a4cfe

Please sign in to comment.