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

Issue setting the chartView.delegate to self. #110

Closed
CQH opened this issue May 27, 2015 · 3 comments
Closed

Issue setting the chartView.delegate to self. #110

CQH opened this issue May 27, 2015 · 3 comments

Comments

@CQH
Copy link

CQH commented May 27, 2015

Hi. This is my first time using iOS Charts. Thanks for making this. But, I'm having an issue while making my first class using the framework.

I'm getting the error Thread 1:EXC_BAD_ACCESS... on the the chartView.delegate = self statement.

I'm sure that it's a simple oversight on my part, but I can't find it. I have Charts.framework listed in the Embedded Binaries and Linked Frameworks and Libraries areas.

On a related note, the commented areas in the class below are also generating errors with the ENUMs. But, I haven't reached those points yet.

Please advise.

Thanks.

import UIKit
import Charts

class ViewController: UIViewController, ChartViewDelegate {
    @IBOutlet var chartView: BarChartView!
    @IBOutlet var sliderX: UISlider!
    @IBOutlet var sliderY: UISlider!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "Title"
        chartView.delegate = self
        chartView.descriptionText = ""
        chartView.noDataTextDescription = "There is no data."
        chartView.drawBarShadowEnabled = false
        chartView.drawValueAboveBarEnabled = true
        chartView.maxVisibleValueCount = 60
        chartView.pinchZoomEnabled = false
        chartView.drawGridBackgroundEnabled = false

        var leftAxis: ChartYAxis = chartView.leftAxis
        leftAxis.labelFont = UIFont.systemFontOfSize(CGFloat(10))
        leftAxis.labelCount = 8
        leftAxis.valueFormatter = NSNumberFormatter()
        leftAxis.valueFormatter?.maximumFractionDigits = 1
        leftAxis.valueFormatter?.negativeSuffix = " $"
        leftAxis.valueFormatter?.positiveSuffix = " $"
//        leftAxis.labelPosition = YAxisLabelPosition.OutsideChart
        leftAxis.spaceTop = CGFloat(0.15)

        var rightAxis: ChartYAxis = chartView.rightAxis
        rightAxis.drawGridLinesEnabled = false
        rightAxis.labelFont = UIFont.systemFontOfSize(CGFloat(10))
        rightAxis.labelCount = 8
        rightAxis.valueFormatter = leftAxis.valueFormatter
        rightAxis.spaceTop = CGFloat(0.15)

//        chartView.legend.position = ChartLegendPosition.BelowChartLeft
//        chartView.legend.form = ChartLegendForm.Square
        chartView.legend.formSize = CGFloat(9)
        chartView.legend.font = UIFont(name: "HelveticaNeue-Light", size: CGFloat(11))!
        chartView.legend.xEntrySpace = CGFloat(4)

        sliderX.value = 11
        sliderY.value = 50

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
@michaelmcguire
Copy link

The line setting the delegate is the first line you are attempting to use the chartView property of your view controller. Because it is an implicitly unwrapped optional, it is probably failing while attempting to retrieve the value (which I'm guessing is nil at that point).

Since you are using @IBOutlet, I'm assuming you are using Storyboards or Xibs. If that is the case, make sure you set the correct module (if you haven't) on the Identity Inspector. Here is an example of my storyboard:

storyboard

@CQH
Copy link
Author

CQH commented May 27, 2015

Bingo. Thanks, Michael!

@CQH CQH closed this as completed May 27, 2015
@hpp-hash
Copy link

hpp-hash commented Sep 2, 2019

Thanks @maciejtrybilo

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