Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented line charts

git-svn-id: https://phppowerpoint.svn.codeplex.com/svn/trunk@63267 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
commit 9794d0e53a2ccb51a523d7749d2ea3c63ca1e647 1 parent 112700a
@maartenba maartenba authored
View
144 Classes/PHPPowerPoint/Shape/Chart/Type/Line.php
@@ -0,0 +1,144 @@
+<?php
+/**
+ * PHPPowerPoint
+ *
+ * Copyright (c) 2009 - 2010 PHPPowerPoint
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * @category PHPPowerPoint
+ * @package PHPPowerPoint_Shape_Chart
+ * @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
+ * @version ##VERSION##, ##DATE##
+ */
+
+
+/**
+ * PHPPowerPoint_Shape_Chart_Type_Line
+ *
+ * @category PHPPowerPoint
+ * @package PHPPowerPoint_Shape_Chart_Type
+ * @copyright Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
+ */
+class PHPPowerPoint_Shape_Chart_Type_Line extends PHPPowerPoint_Shape_Chart_Type implements PHPPowerPoint_IComparable
+{
+ /**
+ * Data
+ *
+ * @var array
+ */
+ private $_data = array();
+
+ /**
+ * Create a new PHPPowerPoint_Shape_Chart_Type_Line instance
+ */
+ public function __construct()
+ {
+ }
+
+ /**
+ * Get Data
+ *
+ * @return array
+ */
+ public function getData() {
+ return $this->_data;
+ }
+
+ /**
+ * Set Data
+ *
+ * @param array $value Array of PHPPowerPoint_Shape_Chart_Series
+ * @return PHPPowerPoint_Shape_Type_Bar3D
+ */
+ public function setData($value = array()) {
+ $this->_data = $value;
+ return $this;
+ }
+
+ /**
+ * Add Series
+ *
+ * @param PHPPowerPoint_Shape_Chart_Series $value
+ * @return PHPPowerPoint_Shape_Type_Bar3D
+ */
+ public function addSeries(PHPPowerPoint_Shape_Chart_Series $value) {
+ $this->_data[] = $value;
+ return $this;
+ }
+
+ /**
+ * Get hash code
+ *
+ * @return string Hash code
+ */
+ public function getHashCode() {
+ $hash = '';
+ foreach ($this->_data as $series) {
+ $hash .= $series->getHashCode();
+ }
+
+ return md5(
+ $hash
+ . __CLASS__
+ );
+ }
+
+ /**
+ * Hash index
+ *
+ * @var string
+ */
+ private $_hashIndex;
+
+ /**
+ * Get hash index
+ *
+ * Note that this index may vary during script execution! Only reliable moment is
+ * while doing a write of a workbook and when changes are not allowed.
+ *
+ * @return string Hash index
+ */
+ public function getHashIndex() {
+ return $this->_hashIndex;
+ }
+
+ /**
+ * Set hash index
+ *
+ * Note that this index may vary during script execution! Only reliable moment is
+ * while doing a write of a workbook and when changes are not allowed.
+ *
+ * @param string $value Hash index
+ */
+ public function setHashIndex($value) {
+ $this->_hashIndex = $value;
+ }
+
+ /**
+ * Implement PHP __clone to create a deep clone, not just a shallow copy.
+ */
+ public function __clone() {
+ $vars = get_object_vars($this);
+ foreach ($vars as $key => $value) {
+ if (is_object($value)) {
+ $this->$key = clone $value;
+ } else {
+ $this->$key = $value;
+ }
+ }
+ }
+}
View
209 Classes/PHPPowerPoint/Writer/PowerPoint2007/Chart.php
@@ -502,6 +502,8 @@ protected function _writePlotArea(PHPPowerPoint_Shared_XMLWriter $objWriter, PHP
$this->_writeTypeBar3D($objWriter, $chartType, $chart->getIncludeSpreadsheet());
} else if ($chartType instanceof PHPPowerPoint_Shape_Chart_Type_Pie3D) {
$this->_writeTypePie3D($objWriter, $chartType, $chart->getIncludeSpreadsheet());
+ } else if ($chartType instanceof PHPPowerPoint_Shape_Chart_Type_Line) {
+ $this->_writeTypeLine($objWriter, $chartType, $chart->getIncludeSpreadsheet());
} else {
throw new Exception('The chart type provided could not be rendered.');
}
@@ -644,6 +646,10 @@ protected function _writePlotArea(PHPPowerPoint_Shared_XMLWriter $objWriter, PHP
$objWriter->writeAttribute('formatCode', $subject->getAxisY()->getFormatCode());
$objWriter->writeAttribute('sourceLinked', '0');
$objWriter->endElement();
+
+ // c:majorGridlines
+ $objWriter->startElement('c:majorGridlines');
+ $objWriter->endElement();
// c:majorTickMark
$objWriter->startElement('c:majorTickMark');
@@ -1258,4 +1264,207 @@ protected function _writeTypePie3D(PHPPowerPoint_Shared_XMLWriter $objWriter, PH
$objWriter->endElement();
}
+
+ /**
+ * Write Type Line
+ *
+ * @param PHPPowerPoint_Shared_XMLWriter $objWriter XML Writer
+ * @param PHPPowerPoint_Shape_Chart_Type_Line $subject
+ * @param boolean $includeSheet
+ * @throws Exception
+ */
+ protected function _writeTypeLine(PHPPowerPoint_Shared_XMLWriter $objWriter, PHPPowerPoint_Shape_Chart_Type_Line $subject, $includeSheet = false) {
+ // c:lineChart
+ $objWriter->startElement('c:lineChart');
+
+ // c:grouping
+ $objWriter->startElement('c:grouping');
+ $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) {
+ // 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);
+
+ // c:spPr
+ $objWriter->startElement('c:spPr');
+
+ // Write fill
+ $this->_writeFill($objWriter, $value);
+
+ $objWriter->endElement();
+
+ $objWriter->endElement();
+ }
+
+ // c:dLbls
+ $objWriter->startElement('c:dLbls');
+
+ // 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()->getBold() ? 'true' : 'false'));
+ $objWriter->writeAttribute('i', ($series->getFont()->getItalic() ? 'true' : 'false'));
+ $objWriter->writeAttribute('strike', ($series->getFont()->getStrikethrough() ? 'sngStrike' : 'noStrike'));
+ $objWriter->writeAttribute('sz', ($series->getFont()->getSize() * 100));
+ $objWriter->writeAttribute('u', $series->getFont()->getUnderline());
+
+ if ($series->getFont()->getSuperScript() || $series->getFont()->getSubScript()) {
+ if ($series->getFont()->getSuperScript()) {
+ $objWriter->writeAttribute('baseline', '30000');
+ } else if ($series->getFont()->getSubScript()) {
+ $objWriter->writeAttribute('baseline', '-25000');
+ }
+ }
+
+ // Font - a:solidFill
+ $objWriter->startElement('a:solidFill');
+
+ // a:srgbClr
+ $objWriter->startElement('a:srgbClr');
+ $objWriter->writeAttribute('val', $series->getFont()->getColor()->getRGB());
+ $objWriter->endElement();
+
+ $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->getShowValue() ? '1' : '0');
+
+ // c:showCatName
+ $this->_writeElementWithValAttribute($objWriter, 'c:showCatName', $series->getShowCategoryName() ? '1' : '0');
+
+ // c:showSerName
+ $this->_writeElementWithValAttribute($objWriter, 'c:showSerName', $series->getShowSeriesName() ? '1' : '0');
+
+ // c:showPercent
+ $this->_writeElementWithValAttribute($objWriter, 'c:showPercent', $series->getShowPercentage() ? '1' : '0');
+
+ // c:showLeaderLines
+ $this->_writeElementWithValAttribute($objWriter, 'c:showLeaderLines', $series->getShowLeaderLines() ? '1' : '0');
+
+ $objWriter->endElement();
+
+ // c:spPr
+ $objWriter->startElement('c:spPr');
+
+ // Write fill
+ $this->_writeFill($objWriter, $series->getFill());
+
+ $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();
+
+ // c:axId
+ $objWriter->startElement('c:axId');
+ $objWriter->writeAttribute('val', '0');
+ $objWriter->endElement();
+
+ $objWriter->endElement();
+ }
}
View
40 Tests/07chart.php
@@ -143,6 +143,46 @@
$shape->getLegend()->getBorder()->setLineStyle(PHPPowerPoint_Style_Border::LINE_SINGLE);
$shape->getLegend()->getFont()->setItalic(true);
+// Create templated slide
+echo date('H:i:s') . " Create templated slide\n";
+$currentSlide = createTemplatedSlide($objPHPPowerPoint); // local function
+
+// Generate sample data for third chart
+echo date('H:i:s') . " Generate sample data for third chart\n";
+$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)\n";
+$lineChart = new PHPPowerPoint_Shape_Chart_Type_Line();
+$series = new PHPPowerPoint_Shape_Chart_Series('Downloads', $seriesData);
+$series->setShowSeriesName(true);
+$lineChart->addSeries($series);
+
+// Create a shape (chart)
+echo date('H:i:s') . " Create a shape (chart)\n";
+$shape = $currentSlide->createChartShape();
+$shape->setName('PHPPowerPoint Daily Downloads')
+ ->setResizeProportional(false)
+ ->setHeight(550)
+ ->setWidth(700)
+ ->setOffsetX(120)
+ ->setOffsetY(80);
+$shape->getShadow()->setVisible(true)
+ ->setDirection(45)
+ ->setDistance(10);
+$shape->getFill()->setFillType(PHPPowerPoint_Style_Fill::FILL_GRADIENT_LINEAR)
+ ->setStartColor(new PHPPowerPoint_Style_Color('FFCCCCCC'))
+ ->setEndColor(new PHPPowerPoint_Style_Color('FFFFFFFF'))
+ ->setRotation(270);
+$shape->getBorder()->setLineStyle(PHPPowerPoint_Style_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(PHPPowerPoint_Style_Border::LINE_SINGLE);
+$shape->getLegend()->getFont()->setItalic(true);
+
// Save PowerPoint 2007 file
echo date('H:i:s') . " Write to PowerPoint2007 format\n";
$objWriter = PHPPowerPoint_IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
Please sign in to comment.
Something went wrong with that request. Please try again.