Adding number formatting to percentages in phpPowerPoint Charts

Below is a patch to add number formatting to percentages in phpPowerPoint Pie Charts:

{{{ lang=diff
Index: Shape/Chart/Series.php
===================================================================
— Shape/Chart/Series.php (revision 71171)
+++ Shape/Chart/Series.php (working copy)
@@ -101,6 +101,15 @@
* @var boolean
*/
private $_showPercentage = false;
+
+ /**
+ * $_percentFormat
+ * Added to set the number format of series percent values.
+ * 2-5-2013 / David Lasley / dave -at- dlasley -dot- net
+ *
+ * @var str (excel number format code)
+ */
+ private $_percentFormat = ‘0.00%’;

/**
* ShowLeaderLines
@@ -301,6 +310,33 @@
$this->_showPercentage = $value;
return $this;
}
+
+ /*
+ * Adding percentage number formats
+ * 2-5-2013 / David Lasley / dave -at- dlasley -dot- net
+ */
+
+ /**
+ * Get percentFormat
+ *
+ * @return str
+ */
+ public function getPercentFormat() {
+ return $this->_percentFormat;
+ }
+
+ /**
+ * Set percentFormat
+ *
+ * @param str $value Excel number format code
+ * @return PHPPowerPoint_Shape_Chart_Series
+ */
+ public function setPercentFormat($value) {
+ $this->_percentFormat = $value;
+ return $this;
+ }
+
+ // End percentage format

/**
* Get ShowLeaderLines
Index: Writer/PowerPoint2007/Chart.php
===================================================================
— Writer/PowerPoint2007/Chart.php (revision 71171)
+++ Writer/PowerPoint2007/Chart.php (working copy)
@@ -1160,7 +1160,15 @@

// c:dLbls
$objWriter->startElement(‘c:dLbls’);

+
+ /*
+ * Adding percentage number formats
+ * 2-5-2013 / David Lasley / dave -at- dlasley -dot- net
+ */
+ // c:numFmt
+ if ($series->getShowPercentage()){
+ $objWriter->startElement(‘c:numFmt’);
+ $objWriter->writeAttribute(‘formatCode’, $series->getPercentFormat());
+ $objWriter->writeAttribute(‘sourceLinked’, ‘0’);
+ $objWriter->endElement();
+ }
+
// c:txPr
$objWriter->startElement(‘c:txPr’);

}}}


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *