Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Can set min and max values for axes. #2751

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/PhpWord/Style/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ class Chart extends AbstractStyle
*/
private $gridX = false;

/**
* Min value for Y-Axis.
*
* @var null|float|int
*/
private $minY;

/**
* Max value for X-Axis.
*
* @var null|float|int
*/
private $minX;

/**
* Max value for Y-Axis.
*
* @var null|float|int
*/
private $maxY;

/**
* Max value for X-Axis.
*
* @var null|float|int
*/
private $maxX;

/**
* Create a new instance.
*
Expand Down Expand Up @@ -551,4 +579,68 @@ public function setShowGridX($value = true)

return $this;
}

/**
* @return null|float|int
*/
public function minY()
{
return $this->minY;
}

/**
* @param null|float|int $minY
*/
public function setMinY($minY): void
{
$this->minY = $minY;
}

/**
* @return null|float|int
*/
public function minX()
{
return $this->minX;
}

/**
* @param null|float|int $minX
*/
public function setMinX($minX): void
{
$this->minX = $minX;
}

/**
* @return null|float|int
*/
public function maxY()
{
return $this->maxY;
}

/**
* @param null|float|int $maxY
*/
public function setMaxY($maxY): void
{
$this->maxY = $maxY;
}

/**
* @return null|float|int
*/
public function maxX()
{
return $this->maxX;
}

/**
* @param null|float|int $maxX
*/
public function setMaxX($maxX): void
{
$this->maxX = $maxX;
}
}
20 changes: 20 additions & 0 deletions src/PhpWord/Writer/Word2007/Part/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,26 @@ private function writeAxis(XMLWriter $xmlWriter, $type): void

$xmlWriter->startElement('c:scaling');
$xmlWriter->writeElementBlock('c:orientation', 'val', 'minMax');
if ($type == 'cat' && $style->minX()) {
$xmlWriter->startElement('c:min');
$xmlWriter->writeAttribute('val', $style->minX());
$xmlWriter->endElement();
}
if ($type == 'cat' && $style->maxX()) {
$xmlWriter->startElement('c:max');
$xmlWriter->writeAttribute('val', $style->maxX());
$xmlWriter->endElement();
}
if ($type == 'val' && $style->minY()) {
$xmlWriter->startElement('c:min');
$xmlWriter->writeAttribute('val', $style->minY());
$xmlWriter->endElement();
}
if ($type == 'val' && $style->maxY()) {
$xmlWriter->startElement('c:max');
$xmlWriter->writeAttribute('val', $style->maxY());
$xmlWriter->endElement();
}
$xmlWriter->endElement(); // c:scaling

$this->writeShape($xmlWriter, true);
Expand Down
Loading