Merge pull request #1 from Stephan212/develop

Add Option for Dynamic Chart Legend Position
This commit is contained in:
csk83 2020-08-25 12:16:15 +08:00 committed by GitHub
commit 9945240ea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -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
*
@ -285,6 +292,35 @@ class Chart extends AbstractStyle
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
*

View File

@ -131,6 +131,7 @@ class Chart extends AbstractPart
$title = $style->getTitle();
$showLegend = $style->isShowLegend();
$legendPosition = $style->getLegendPosition();
//Chart title
if ($title) {
@ -154,7 +155,7 @@ class Chart extends AbstractPart
//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');