Skip to content

Commit

Permalink
Get plotVisOnly and dispBlanksAs props from chart in Xlsx Chart Writer.
Browse files Browse the repository at this point in the history
These chart properties where hardcoded in the Xlsx writer, ignoring the
values passed to the \PhpOffice\PhpSpreadsheet\Chart\Chart class constructor.

I also changed the default $displayBlanksAs value to 'gap' to match this
document:
https://docs.microsoft.com/en-us/openspecs/office_standards/ms-oi29500/1942c028-3c4e-4dd9-a379-b12a9b7914df

Closes #1266
  • Loading branch information
guicapanema authored and PowerKiKi committed Nov 30, 2019
1 parent d61855e commit 144a0ca
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Do not confuse defined names and cell refs [#1263](https://github.com/PHPOffice/PhpSpreadsheet/pull/1263)
- XLSX reader/writer keep decimal for floats with a zero decimal part [#1262](https://github.com/PHPOffice/PhpSpreadsheet/pull/1262)
- ODS writer prevent invalid numeric value if locale decimal separator is comma [#1268](https://github.com/PHPOffice/PhpSpreadsheet/pull/1268)
- Xlsx writer actually writes plotVisOnly and dispBlanksAs from chart properties [#1266](https://github.com/PHPOffice/PhpSpreadsheet/pull/1266)

## [1.10.0] - 2019-11-18

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Chart/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Chart
* @param null|GridLines $majorGridlines
* @param null|GridLines $minorGridlines
*/
public function __construct($name, Title $title = null, Legend $legend = null, PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = '0', Title $xAxisLabel = null, Title $yAxisLabel = null, Axis $xAxis = null, Axis $yAxis = null, GridLines $majorGridlines = null, GridLines $minorGridlines = null)
public function __construct($name, Title $title = null, Legend $legend = null, PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = 'gap', Title $xAxisLabel = null, Title $yAxisLabel = null, Axis $xAxis = null, Axis $yAxis = null, GridLines $majorGridlines = null, GridLines $minorGridlines = null)
{
$this->name = $name;
$this->title = $title;
Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Writer/Xlsx/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public function writeChart(\PhpOffice\PhpSpreadsheet\Chart\Chart $pChart, $calcu
$this->writeLegend($objWriter, $pChart->getLegend());

$objWriter->startElement('c:plotVisOnly');
$objWriter->writeAttribute('val', 1);
$objWriter->writeAttribute('val', (int) $pChart->getPlotVisibleOnly());
$objWriter->endElement();

$objWriter->startElement('c:dispBlanksAs');
$objWriter->writeAttribute('val', 'gap');
$objWriter->writeAttribute('val', $pChart->getDisplayBlanksAs());
$objWriter->endElement();

$objWriter->startElement('c:showDLblsOverMax');
Expand Down

1 comment on commit 144a0ca

@myjobrajesh
Copy link

Choose a reason for hiding this comment

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

Perfect match found. Thanks for saving my time.

Please sign in to comment.