Skip to content

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

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

Open
wants to merge 1 commit 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;
}
Comment on lines +594 to +597
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function setMinY($minY): void
{
$this->minY = $minY;
}
public function setMinY($minY): self
{
$this->minY = $minY;
return $this;
}

@jfoucher Can you return $this for each setter, please ?


/**
* @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