Skip to content

Commit

Permalink
Merge pull request #4074 from yfinkel/patch-1
Browse files Browse the repository at this point in the history
Update JpGraphRendererBase.php - check existing of PlotLabel
  • Loading branch information
oleibman authored Jun 30, 2024
2 parents d767d46 + 675efc1 commit aae4992
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ private function renderRadarPlotArea(): void
$this->renderTitle();
}

private function getDataLabel(int $groupId, int $index): mixed
{
$plotLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupId)->getPlotLabelByIndex($index);
if (!$plotLabel) {
return '';
}

return $plotLabel->getDataValue();
}

private function renderPlotLine(int $groupID, bool $filled = false, bool $combination = false): void
{
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
Expand Down Expand Up @@ -334,8 +344,8 @@ 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();
$seriesPlot->SetLegend($dataLabel);

$seriesPlot->SetLegend($this->getDataLabel($groupID, $index));

$seriesPlots[] = $seriesPlot;
}
Expand Down Expand Up @@ -408,12 +418,8 @@ private function renderPlotBar(int $groupID, ?string $dimensions = '2d'): void
if ($dimensions == '3d') {
$seriesPlot->SetShadow();
}
if (!$this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) {
$dataLabel = '';
} else {
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue();
}
$seriesPlot->SetLegend($dataLabel);

$seriesPlot->SetLegend($this->getDataLabel($groupID, $j));

$seriesPlots[] = $seriesPlot;
}
Expand Down Expand Up @@ -492,8 +498,7 @@ private function renderPlotScatter(int $groupID, bool $bubble): void
$marker = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
$this->formatPointMarker($seriesPlot, $marker);
}
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
$seriesPlot->SetLegend($dataLabel);
$seriesPlot->SetLegend($this->getDataLabel($groupID, $i));

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

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

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

$this->graph->Add($seriesPlot);
}
Expand Down

0 comments on commit aae4992

Please sign in to comment.