Charts: (v3.0 + Swift3.0)LineChart crash when dataSets is a empty array

Created on 20 Sep 2016  Â·  11Comments  Â·  Source: danielgindi/Charts

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

bug

All 11 comments

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

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

2016-09-21 5 30 56
master -> Charts 3.0

@liuxuan30

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

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

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.

@danielgindi reopened

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

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

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
}

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()
        }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aungbandlab picture Aungbandlab  Â·  4Comments

kwstasna picture kwstasna  Â·  3Comments

anhltse03448 picture anhltse03448  Â·  3Comments

brytnvmg picture brytnvmg  Â·  4Comments

ahmedsafadii picture ahmedsafadii  Â·  3Comments