Skip to content

Commit

Permalink
Merge pull request #1 from Stephan212/develop
Browse files Browse the repository at this point in the history
Add Option for Dynamic Chart Legend Position
  • Loading branch information
csk83 authored Aug 25, 2020
2 parents 21f4bb3 + 90a8900 commit 9945240
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/PhpWord/Style/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class Chart extends AbstractStyle
*/
private $showLegend = false;

/**
* Chart legend Position.
*
* @var string
*/
private $legendPosition = 'r';

/**
* A list of display options for data labels
*
Expand Down Expand Up @@ -285,6 +292,35 @@ public function setShowLegend($value = false)
return $this;
}

/**
* Get chart legend position
*
* @return string
*/
public function getLegendPosition()
{
return $this->legendPosition;
}

/**
* Set chart legend position. choices:
* "r" - right of chart
* "b" - bottom of chart
* "t" - top of chart
* "l" - left of chart
* "tr" - top right of chart
*
* default: right
*
* @param bool $value
*/
public function setLegendPosition($value = 'r')
{
$this->legendPosition = $value;

return $this;
}

/*
* Show labels for axis
*
Expand Down
3 changes: 2 additions & 1 deletion src/PhpWord/Writer/Word2007/Part/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private function writePlotArea(XMLWriter $xmlWriter)

$title = $style->getTitle();
$showLegend = $style->isShowLegend();
$legendPosition = $style->getLegendPosition();

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

//Chart legend
if ($showLegend) {
$xmlWriter->writeRaw('<c:legend><c:legendPos val="r"/></c:legend>');
$xmlWriter->writeRaw('<c:legend><c:legendPos val="'.$legendPosition.'"/></c:legend>');
}

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

0 comments on commit 9945240

Please sign in to comment.