-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
fix for crash when interval is NaN #2804
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2804 +/- ##
=========================================
- Coverage 19.64% 19.54% -0.1%
=========================================
Files 113 113
Lines 13791 13878 +87
=========================================
+ Hits 2709 2713 +4
- Misses 11082 11165 +83
Continue to review full report at Codecov.
|
#2377 is my thought to fix. Have you checked it's the reason why you saw NaN on your side? |
I looked at your change again, it seems not the same thing. In the code, min/max are coming from: @objc open func computeAxis(min: Double, max: Double, inverted: Bool)
{
var min = min, max = max
if let transformer = self.transformer
{
// calculate the starting and entry point of the y-labels (depending on zoom / contentrect bounds)
if let viewPortHandler = viewPortHandler
{
if viewPortHandler.contentWidth > 10.0 && !viewPortHandler.isFullyZoomedOutY
{
let p1 = transformer.valueForTouchPoint(CGPoint(x: viewPortHandler.contentLeft, y: viewPortHandler.contentTop))
let p2 = transformer.valueForTouchPoint(CGPoint(x: viewPortHandler.contentLeft, y: viewPortHandler.contentBottom))
if !inverted
{
min = Double(p2.y)
max = Double(p1.y)
}
else
{
min = Double(p1.y)
max = Double(p2.y)
}
}
}
}
computeAxisValues(min: min, max: max)
} which basically take the contentRect coordinates to calculate. If this goes wrong, the chart setup is a mess in the first place then, which should not happen at all. Adding a NaN check is the last resort to prevent crash, but we don't want to silent the crash first, it will be more difficult to notice. |
please open an issue to track NaN crash for your case, with details or values that causes NaN, thanks. |
I am not able to open an issue with actual code for about two weeks, as I am away. However, it happens roughly when you do something like in the SO issue. In my case, the steps go like this:
I will open an actual issue with code once I am back. |
+1 Having the same issue. |
I logged the reason in #2845 why closing this. |
@liuxuan30 override var data: ChartData? {
get { return super.data }
set {
guard let newData = newValue, newData.entryCount > 0 else {
super.data = ChartData(dataSet: ChartDataSet(values: [ChartDataEntry()]))
return
}
super.data = newData
notifyDataSetChanged()
}
} |
Hello @SeRG1k17 I had same issue too but no other solutions worked for me where should I put your code ? Thanks |
I have solved the issue using following answer https://stackoverflow.com/questions/45496912/how-to-clear-a-chart-and-then-add-data-to-it-in-swift-3-using-chartview-clear |
After clearing a working chart and then adding new data (dataset), the chart crashes in AxisRendererBase.swift line 125 with "Double value cannot be converted to Int because it is either infinite or NaN". The reason for that is "min" and "max" are NaN (because the Transformer._matrixValueToPx is somewhat invalid(?), why does it happen?).
The issue is referenced here: https://stackoverflow.com/questions/45496912/how-to-clear-a-chart-and-then-add-data-to-it-in-swift-3-using-chartview-clear and here: #2168 (josman185hotm's comment from 17 Jun).