Skip to content

Commit aae4992

Browse files
authored
Merge pull request #4074 from yfinkel/patch-1
Update JpGraphRendererBase.php - check existing of PlotLabel
2 parents d767d46 + 675efc1 commit aae4992

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ private function renderRadarPlotArea(): void
281281
$this->renderTitle();
282282
}
283283

284+
private function getDataLabel(int $groupId, int $index): mixed
285+
{
286+
$plotLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupId)->getPlotLabelByIndex($index);
287+
if (!$plotLabel) {
288+
return '';
289+
}
290+
291+
return $plotLabel->getDataValue();
292+
}
293+
284294
private function renderPlotLine(int $groupID, bool $filled = false, bool $combination = false): void
285295
{
286296
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
@@ -334,8 +344,8 @@ private function renderPlotLine(int $groupID, bool $filled = false, bool $combin
334344
// Set the appropriate plot marker
335345
$this->formatPointMarker($seriesPlot, $marker);
336346
}
337-
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($index)->getDataValue();
338-
$seriesPlot->SetLegend($dataLabel);
347+
348+
$seriesPlot->SetLegend($this->getDataLabel($groupID, $index));
339349

340350
$seriesPlots[] = $seriesPlot;
341351
}
@@ -408,12 +418,8 @@ private function renderPlotBar(int $groupID, ?string $dimensions = '2d'): void
408418
if ($dimensions == '3d') {
409419
$seriesPlot->SetShadow();
410420
}
411-
if (!$this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) {
412-
$dataLabel = '';
413-
} else {
414-
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue();
415-
}
416-
$seriesPlot->SetLegend($dataLabel);
421+
422+
$seriesPlot->SetLegend($this->getDataLabel($groupID, $j));
417423

418424
$seriesPlots[] = $seriesPlot;
419425
}
@@ -492,8 +498,7 @@ private function renderPlotScatter(int $groupID, bool $bubble): void
492498
$marker = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
493499
$this->formatPointMarker($seriesPlot, $marker);
494500
}
495-
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
496-
$seriesPlot->SetLegend($dataLabel);
501+
$seriesPlot->SetLegend($this->getDataLabel($groupID, $i));
497502

498503
$this->graph->Add($seriesPlot);
499504
}
@@ -524,13 +529,12 @@ private function renderPlotRadar(int $groupID): void
524529

525530
$seriesPlot = new RadarPlot(array_reverse($dataValuesX));
526531

527-
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
528532
$seriesPlot->SetColor(self::$colourSet[self::$plotColour++]);
529533
if ($radarStyle == 'filled') {
530534
$seriesPlot->SetFillColor(self::$colourSet[self::$plotColour]);
531535
}
532536
$this->formatPointMarker($seriesPlot, $marker);
533-
$seriesPlot->SetLegend($dataLabel);
537+
$seriesPlot->SetLegend($this->getDataLabel($groupID, $i));
534538

535539
$this->graph->Add($seriesPlot);
536540
}

0 commit comments

Comments
 (0)