Skip to content

Commit 246bfcf

Browse files
committed
Add setName Method for Chart
Addresses a problem identified in issue PHPOffice#2991. Chart name is set in constructor, but there is no method to subsequently change it. This PR adds a method to do so.
1 parent c34662b commit 246bfcf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/PhpSpreadsheet/Chart/Chart.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ public function getName()
188188
return $this->name;
189189
}
190190

191+
public function setName(string $name): self
192+
{
193+
$this->name = $name;
194+
195+
return $this;
196+
}
197+
191198
/**
192199
* Get Worksheet.
193200
*/

tests/PhpSpreadsheetTests/Chart/ChartMethodTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ public function testMethodVsConstructor(): void
9393
$xAxis, // xAxis
9494
$yAxis // yAxis
9595
);
96-
$chart2 = new Chart('chart1');
96+
$chart2 = new Chart('xyz');
9797
$chart2
98+
->setName('chart1')
9899
->setLegend($legend)
99100
->setPlotArea($plotArea)
100101
->setPlotVisibleOnly(true)

0 commit comments

Comments
 (0)