Skip to content

Commit 9945240

Browse files
authored
Merge pull request #1 from Stephan212/develop
Add Option for Dynamic Chart Legend Position
2 parents 21f4bb3 + 90a8900 commit 9945240

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/PhpWord/Style/Chart.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class Chart extends AbstractStyle
6666
*/
6767
private $showLegend = false;
6868

69+
/**
70+
* Chart legend Position.
71+
*
72+
* @var string
73+
*/
74+
private $legendPosition = 'r';
75+
6976
/**
7077
* A list of display options for data labels
7178
*
@@ -285,6 +292,35 @@ public function setShowLegend($value = false)
285292
return $this;
286293
}
287294

295+
/**
296+
* Get chart legend position
297+
*
298+
* @return string
299+
*/
300+
public function getLegendPosition()
301+
{
302+
return $this->legendPosition;
303+
}
304+
305+
/**
306+
* Set chart legend position. choices:
307+
* "r" - right of chart
308+
* "b" - bottom of chart
309+
* "t" - top of chart
310+
* "l" - left of chart
311+
* "tr" - top right of chart
312+
*
313+
* default: right
314+
*
315+
* @param bool $value
316+
*/
317+
public function setLegendPosition($value = 'r')
318+
{
319+
$this->legendPosition = $value;
320+
321+
return $this;
322+
}
323+
288324
/*
289325
* Show labels for axis
290326
*

src/PhpWord/Writer/Word2007/Part/Chart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private function writePlotArea(XMLWriter $xmlWriter)
131131

132132
$title = $style->getTitle();
133133
$showLegend = $style->isShowLegend();
134+
$legendPosition = $style->getLegendPosition();
134135

135136
//Chart title
136137
if ($title) {
@@ -154,7 +155,7 @@ private function writePlotArea(XMLWriter $xmlWriter)
154155

155156
//Chart legend
156157
if ($showLegend) {
157-
$xmlWriter->writeRaw('<c:legend><c:legendPos val="r"/></c:legend>');
158+
$xmlWriter->writeRaw('<c:legend><c:legendPos val="'.$legendPosition.'"/></c:legend>');
158159
}
159160

160161
$xmlWriter->startElement('c:plotArea');

0 commit comments

Comments
 (0)