From f34e0ead2991e07d4868553ea623f4f6f121a5cb Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Fri, 12 Aug 2022 20:10:45 -0700 Subject: [PATCH] Add setName Method for Chart (#3001) Addresses a problem identified in issue #2991. Chart name is set in constructor, but there is no method to subsequently change it. This PR adds a method to do so. --- src/PhpSpreadsheet/Chart/Chart.php | 7 +++++++ tests/PhpSpreadsheetTests/Chart/ChartMethodTest.php | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Chart/Chart.php b/src/PhpSpreadsheet/Chart/Chart.php index 556b0eff..b962978d 100644 --- a/src/PhpSpreadsheet/Chart/Chart.php +++ b/src/PhpSpreadsheet/Chart/Chart.php @@ -188,6 +188,13 @@ class Chart return $this->name; } + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } + /** * Get Worksheet. */ diff --git a/tests/PhpSpreadsheetTests/Chart/ChartMethodTest.php b/tests/PhpSpreadsheetTests/Chart/ChartMethodTest.php index 027ddc53..5c3622ad 100644 --- a/tests/PhpSpreadsheetTests/Chart/ChartMethodTest.php +++ b/tests/PhpSpreadsheetTests/Chart/ChartMethodTest.php @@ -93,8 +93,9 @@ class ChartMethodTest extends TestCase $xAxis, // xAxis $yAxis // yAxis ); - $chart2 = new Chart('chart1'); + $chart2 = new Chart('xyz'); $chart2 + ->setName('chart1') ->setLegend($legend) ->setPlotArea($plotArea) ->setPlotVisibleOnly(true)