Skip to content
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

(v3.0 + Swift3.0)LineChart crash when dataSets is a empty array #1491

Closed
Huang-Libo opened this issue Sep 20, 2016 · 11 comments
Closed

(v3.0 + Swift3.0)LineChart crash when dataSets is a empty array #1491

Huang-Libo opened this issue Sep 20, 2016 · 11 comments
Labels

Comments

@Huang-Libo
Copy link

Huang-Libo commented Sep 20, 2016

in v2.x, when LineChart's dataSets is a empty array it will show a charts with no line, but v3.0 will crash.

error info:
fatal error: Double value cannot be converted to Int because it is either infinite or NaN

@danielgindi
Copy link
Collaborator

Try with latest master, there's a commit from a few hours ago that is supposed to fix that

@Huang-Libo
Copy link
Author

@danielgindi
I noticed the commit that you mentioned, and my version is just updated, but still crash.

@liuxuan30 liuxuan30 added the bug label Sep 21, 2016
@monkeyRing
Copy link

monkeyRing commented Sep 21, 2016

2016-09-21 5 30 56

master -> Charts 3.0

@liuxuan30

@danielgindi
Copy link
Collaborator

This is fixed now due to another issue that has pointed out the source of the issue (#1511)

@Huang-Libo
Copy link
Author

I'm at the head of master branch, but still crash..

@apurva
Copy link

apurva commented Sep 23, 2016

I can confirm that the fix does NOT work. Stepping through the code, I can see that the Number value
starts at 1.7976931348623157E+308 and goes over the protection. However, in this case,

let i = roundToNextSignificant(number: Double(number))

results in making i = infinity and then

Int(ceil(-log10(i))) + 2

goes on to crash the app.

Why the initial number value is the max double value is beyond me though.

@liuxuan30
Copy link
Member

@danielgindi reopened

@liuxuan30 liuxuan30 reopened this Sep 26, 2016
@pmairoldi
Copy link
Collaborator

Same issue as #1550. Should be fixed by #1558.

@quicklywilliam
Copy link

This issue is still at large. You can see the illegal conversion on this line (it tries to convert it to an Int inside the call to roundToNextSignificant):

https://github.com/danielgindi/Charts/blob/master/Source/Charts/Renderers/AxisRendererBase.swift#L125

@quicklywilliam
Copy link

If anyone is looking for a workaround for this without patching, just set custom axis min and max before setting the data on the chart, i.e.:

if (dataArray.count == 0) {
                chartView.xAxis.axisMinimum = 0
               chartView.xAxis.axisMaximum = 10
                
                chartView.leftAxis.axisMinimum = 0
                chartView.leftAxis.axisMaximum = 10
                chartView.rightAxis.axisMinimum = 0
                chartView.rightAxis.axisMaximum = 10
}

@semireg
Copy link

semireg commented Oct 14, 2017

We're seeing this only when the chart is zoomed and we empty the data. Setting the above axisMin/Max to (0,10) respectively, worked, but then you'd need to disable this custom min/max later.

Since our issue only happens when zoomed, we found that zooming out bypassed the crash. However, resetZoom() doesn't seem to work. Instead, we use:

        while !chartView.isFullyZoomedOut {
            chartView.zoomOut()
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants