kevinzhow / PNChart

A simple and beautiful chart lib used in Piner and CoinsMan for iOS
MIT License
9.71k stars 1.76k forks source link

PNBarChart Can't work: yValues Error! #157

Open goocarlos opened 9 years ago

goocarlos commented 9 years ago

I use PNChart v0.7.5 with Swift at a New Project.

class ViewController: UIViewController {

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

        var barChart = PNBarChart(frame: CGRectMake(0, 5.0, CGFloat(600), 145.0))
        barChart.backgroundColor = UIColor.clearColor()
        barChart.xLabels = ["Lun","Mar","Mie","Jue","Vie","Sab","Dom"]
        barChart.yValues = [83,204,102,108,300]
        barChart.strokeColor = UIColor(red:0.09, green:0.7, blue:0.55, alpha:1)
        barChart.strokeChart()
    }

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

}

2015-02-05 5 26 49

adoxner commented 9 years ago

I've been working with this library with Swift as well, and have had to make a few changes to make it more Swift-friendly. You can take a peek/fork them here: https://github.com/adoxner/PNChart

mojtabacazi commented 9 years ago

Have nothing to do with swift! yLabelFormatter function pointer (block) is missing and there is no default for it. Here is how you can fix it

PNBarChart * barChart = [[PNBarChart alloc] initWithFrame:frame];
//Do whatever
barChart.yLabelFormatter = ^(CGFloat yValue){
             return [NSString stringWithFormat:@"%1.f",yValue];
        };
//Now do setY and SetX
[barChart setYValues:...];

Note that I used barChart as an example, this can be applied to any PNChart.

acroventus commented 9 years ago

The problem is that you're adding 7 values on the XLabels and just 5 in YValues. It has to be the same number. The YLabels appear on your bar chart? I can't get them to work.

mojtabacazi commented 9 years ago

@acroventus That is a different thing, I don't think it's related to yLabelFormatter not being defined anywhere.

acroventus commented 9 years ago

@mojtabacazi I think you're right but It might help anyways. I'm having troubles showing my YLabels on the bar chart with swift. I publish the new Issue, can you give me a hand with that please?

mojtabacazi commented 9 years ago

@acroventus sure, but not seeing any new issue, link?

acroventus commented 9 years ago

@mojtabacazi Here's the link for the issue on the Swift version: https://github.com/kevinzhow/PNChart-Swift/issues/31

lamfete commented 9 years ago

this work for me

screen shot 2015-02-24 at 10 37 54 am

cbouvier15 commented 9 years ago

@goocarlos: based in your example and the corrections made by @adoxner, just replacing the conflicting line with the fixed in the @adoxner code, your example works fine.

luao419 commented 9 years ago

I am a beginner for iOS and really need some help from here. It has a question when I run this PNChart on the Ojb-C version.It seems like there is no such head file named UICountingLabel.h in the project. So...how can I fix this problem? 2015-05-04 4 31 15