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

Crash when using BarChartDataSet with BarChartData #4040

Closed
1 task done
spencerkohan opened this issue Jun 24, 2019 · 2 comments
Closed
1 task done

Crash when using BarChartDataSet with BarChartData #4040

spencerkohan opened this issue Jun 24, 2019 · 2 comments

Comments

@spencerkohan
Copy link

spencerkohan commented Jun 24, 2019

What did you do?

I'm attempting to implement a simple bar chart. I've instantiated the data like so:

    let chartView = BarChartView(frame: chartContainer.bounds)
    let data = (0..<10).map { (i) -> BarChartDataEntry in
        return BarChartDataEntry(x: Double(i), y: Double.random(in: 1..<10))
    }
    
    let dataset: BarChartDataSet = BarChartDataSet(data)
    let chartData: BarChartData = BarChartData(dataSets: [dataset])
    
    guard (chartData.dataSets.first as? IBarChartDataSet) != nil else {
        print("WTF???")
        return
    }

    chartView.data = chartData

What did you expect to happen?

I expect that there is not a crash when the chart is loaded.

What happened instead?

There is a crash inside BarChartRenderer-initBuffers on line 76:

let set = barData.dataSets[i] as! IBarChartDataSet

For some reason, the dataset no longer conforms to IBarChartDataSet when it reaches this point.

I have also checked immediately after initializing the BarChartData, and it's already broken there:

    let dataset: BarChartDataSet = BarChartDataSet(data)
    let chartData: BarChartData = BarChartData(dataSets: [dataset])

    // this guard passes: dataset is an IBarChartDataSet
    guard (dataset as? IBarChartDataSet) != nil else { 
        return
    }

    // this one fails.  shouldn't it be the same?
    guard (chartData.dataSets.first as? IBarChartDataSet) != nil else {
        print("WTF???")
        return
    }

Charts Environment

Charts version/Branch/Commit Number: 3.0/master/e850593
Xcode version: 10.2.1
Swift version: 5.0
Platform(s) running Charts: iOS
macOS version running Xcode: 10.14.5

@glisom
Copy link

glisom commented Oct 3, 2019

Any work around on this??

@liuxuan30
Copy link
Member

I suggest you take a look at ChartsDemo and try reproduce with it

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

No branches or pull requests

3 participants