-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update JpGraphRendererBase.php - check existing of PlotLabel #4074
Conversation
I've got Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\FatalError: "Error: Uncaught Error: Call to a member function getDataValue() on bool in .../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php:337 I found that it's necessary to check existing of PlotLabel before using its method getDataValue().
I'v got that: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\FatalError: "Error: Uncaught Error: Call to a member function getDataValue() on bool in .../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php:337 I've found that it's necessary to check existing of PlotLabel before using its method getDataValue().
$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(); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I can't, because I use a big xlsx file in my project, which causes a crash
in this place. I can't localize the issue in this file, because it's very
big with many formulae and charts. But this change solved the problem for
me.
…--
Yury Finkel
ср, 26 июн. 2024 г. в 11:39, oleibman ***@***.***>:
***@***.**** commented on this pull request.
------------------------------
In src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php
<#4074 (comment)>
:
> @@ -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();
+ }
Also, please add a unit test to demonstrate that there was a problem
before your fix and you've fixed it.
—
Reply to this email directly, view it on GitHub
<#4074 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD5LHW6BVAGMDT25P77GE63ZJJV3PAVCNFSM6AAAAABJ5GPLY2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCNBQHE4DSOBSGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Without an example, I am not completely unwilling to proceed, but I am a little reluctant. However, reworking your change will make me a little less reluctant. There are 4 places in JpGraphRendererBase where dataLabel is set.
If you were to make the code from renderPlotBar into a subroutine, and change each of these 4 instances to call the new subroutine instead of assigning a value to dataLabel directly, we would have some assurance that the other 3 are using code which is already tested. If you can confirm that the works in your case, I could proceed. As a bonus, we won't have to deal with the same situation for Radar and Scatter when someone comes across a similar situation with those in future. Something like (untested): private function assignDataLabel(DataSeries $groupId, int $index): mixed
{
if (!$this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($index)) {
$dataLabel = '';
} else {
$dataLabel = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($index)->getDataValue();
}
return $dataLabel;
} |
Well, I updated the code. The function name is getDataLabel(). It works well in my project. I will reappear only after a month, so do what you want with it. It's enough for me that it works for me. |
Thank you for your contribution. |
I've got
Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\FatalError: "Error: Uncaught Error: Call to a member function getDataValue() on bool in .../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Chart/Renderer/JpGraphRendererBase.php:337
I found that it's necessary to check existing of PlotLabel before using its method getDataValue().
This is:
Checklist:
Why this change is needed?
Provide an explanation of why this change is needed, with links to any Issues (if appropriate).
If this is a bugfix or a new feature, and there are no existing Issues, then please also create an issue that will make it easier to track progress with this PR.