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

JBBarChartView does not display all the bars #124

Closed
nikalra opened this issue Nov 15, 2014 · 3 comments
Closed

JBBarChartView does not display all the bars #124

nikalra opened this issue Nov 15, 2014 · 3 comments

Comments

@nikalra
Copy link
Contributor

nikalra commented Nov 15, 2014

I tried setting up a tests class with a bar graph but on iOS 8.1, it seems that one of the bars is missing/not displayed (image below). This happens in both the Simulator and on the iPhone.

I've also copied all of my code below.

Thanks!

screenshot 2014-11-14 18 49 57

import UIKit
import JBChart

class FirstViewController: UIViewController, JBBarChartViewDelegate, JBBarChartViewDataSource {

    var barChartView: JBBarChartView?
    var chartLegend = ["11-14", "11-15", "11-16", "11-17", "11-18", "11-19", "11-20"]
    var chartData = [70, 80.0, 76, 88, 90, 69, 74]

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        barChartView = JBBarChartView()
        barChartView!.frame = CGRectMake(20, 20, self.view.bounds.width - 40, self.view.bounds.height * 0.5)
        barChartView!.backgroundColor = UIColor.darkGrayColor()
        barChartView!.delegate = self
        barChartView!.dataSource = self
        view.addSubview(barChartView!)

        var footerView = FooterView()
        footerView.leftLabel.text = chartLegend[0];
        footerView.rightLabel.text = chartLegend[chartLegend.count - 1 ];
        barChartView!.footerView = footerView

        barChartView!.reloadData()

    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        view.setNeedsLayout()
        barChartView!.reloadData()
    }

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


    // MARK: JBBarChartView

    func numberOfBarsInBarChartView(barChartView: JBBarChartView!) -> UInt {
        return UInt(chartData.count)
    }

    func barChartView(barChartView: JBBarChartView!, heightForBarViewAtIndex index: UInt) -> CGFloat {
        let height = CGFloat(chartData[Int(index)])
        println("Index: \(index); Height: \(height)")
        return height
    }

    func barChartView(barChartView: JBBarChartView!, colorForBarViewAtIndex index: UInt) -> UIColor! {
        println("Color for index \(index)")
        return (index % 2 == 0) ? UIColor.greenColor() : UIColor.blueColor()
    }
@terryworona
Copy link
Collaborator

Set:

barChartView.minimumValue = 0.0f;

@DirkLXX
Copy link

DirkLXX commented Nov 18, 2014

the normalisation issue - smallest value looks like empty. I added a 0 value entry at the end. worked great , too.

@csmobile
Copy link

Hi DirkLXX,
any chance you can elaborate on adding a 0 value entry at the end? Did you add that to the array that acts as the datasource for the chart? For me this just seems to place the blank bar (corresponding to the smallest value in the array) at the end. Thoughts? Thank you so much in advance.

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

4 participants