Skip to content

Commit

Permalink
Can set min and max values for axes. Fixes PHPOffice#1756 and PHPOffi…
Browse files Browse the repository at this point in the history
  • Loading branch information
jfoucher committed Feb 18, 2025
1 parent cdf3d31 commit b0be806
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/PhpWord/Style/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,35 @@ class Chart extends AbstractStyle
*/
private $gridX = false;

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

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

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

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


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

return $this;
}


public function minY(): float|int
{
return $this->minY;
}

public function setMinY(float|int $minY): void
{
$this->minY = $minY;
}

public function minX(): float|int
{
return $this->minX;
}

public function setMinX(float|int $minX): void
{
$this->minX = $minX;
}

public function maxY(): float|int
{
return $this->maxY;
}

public function setMaxY(float|int $maxY): void
{
$this->maxY = $maxY;
}

public function maxX(): float|int
{
return $this->maxX;
}

public function setMaxX(float|int $maxX): void
{
$this->maxX = $maxX;
}
}
12 changes: 12 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,18 @@ private function writeAxis(XMLWriter $xmlWriter, $type): void

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

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

0 comments on commit b0be806

Please sign in to comment.