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

accessing .rightAxis gives EXC_BAD_ACCESS #2082

Closed
mcsquaredjr opened this issue Jan 16, 2017 · 4 comments
Closed

accessing .rightAxis gives EXC_BAD_ACCESS #2082

mcsquaredjr opened this issue Jan 16, 2017 · 4 comments

Comments

@mcsquaredjr
Copy link

Hello,

I'm trying to build a BarChart, which is embedded into a UITableViewCell. The code below works fine, but when I'm trying to disable rightAxis, I'm getting EXC_BAD_ACCESS. Doing the same for the left axis works just fine. Any ideas?

Another funny observation. When I'm disabling the leftAxis, the right axis disappears on my chart.

I'm trying to wrap my head around this for the last couple of days, but no luck so far... Help is much appreciated. Here the code:

import UIKit
import Charts

class ChartCell: UITableViewCell {

@IBOutlet weak var chart: BarChartView!
override func awakeFromNib() {
    super.awakeFromNib()
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    configureChart()
}

func buildChart(data: [DiffPoint]) {
    var diffEntries = [ChartDataEntry]()
    var diffMonth = [String]()
    var i = 0
    for diffPoint in data {
        let diffEntry = BarChartDataEntry(x: Double(i), y: diffPoint.value)
        diffEntries.append(diffEntry)
        diffMonth.append(diffPoint.date)
        i += 1
    }
    
    let chartDataSet = BarChartDataSet(values: diffEntries, label: "")
    chartDataSet.colors = ChartColorTemplates.material()
    let chartData = BarChartData(dataSets: [chartDataSet])
    chartData.setDrawValues(false)
    chart.data = chartData
    // TODO: Animation
}

func configureChart() {
    chart.chartDescription?.text = ""
    chart.xAxis.drawGridLinesEnabled = false
    chart.xAxis.labelTextColor = UIColor.white
    chart.leftAxis.drawGridLinesEnabled = true
    chart.leftAxis.enabled = false
    // the following line gives me error!!!
    chart.rightAxis.enabled = false
    chart.backgroundColor = WWColors.Asphalt
    chart.legend.enabled = false
    chart.highlighter = nil
}    

}

Thanks a lot!

@smawpaw
Copy link

smawpaw commented Jan 16, 2017

Interesting. What happens if instead of disabling the rightAxis you simply disable all it's draw* Bools? I think it has more or less the same effect (visually) as outright disabling the axis

rightAxis.enabled = true // you could skip this line altogether
rightAxis.drawLabelsEnabled = false
rightAxis.drawGridLinesEnabled = false
rightAxis.drawAxisLineEnabled = false

@mcsquaredjr
Copy link
Author

mcsquaredjr commented Jan 16, 2017 via email

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 17, 2017

as far as I can tell,

    internal override func initialize()
    {
        super.initialize()
        
        _leftAxis = YAxis(position: .left)
        _rightAxis = YAxis(position: .right)

is where you start debugging. Don't forget to check out ChartsDemo first..

@mcsquaredjr
Copy link
Author

I spent some time debugging the issue -- my observations made me to believe that somehow Xcode and carthage screwed up my environment. I was able to access the property in debugger, but not when I was running the code on the device.

Anyways, I re-created the project and it all started to work. I'm closing the issue. Thank, everyone, who responded.

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