Skip to content
Merged
4 changes: 3 additions & 1 deletion src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ private function renderPlotLine(int $groupID, bool $filled = false, bool $combin
// Set the appropriate plot marker
$this->formatPointMarker($seriesPlot, $marker);
}
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($index)->getDataValue();
if ($this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($index)) {
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($index)->getDataValue();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think seriesPlot->SetLegend($dataLabel) needs to be inside the if statement, otherwise dataLabel will not be defined.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, please add a unit test to demonstrate that there was a problem before your fix and you've fixed it.

$seriesPlot->SetLegend($dataLabel);

$seriesPlots[] = $seriesPlot;
Expand Down