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

Problem with Formatter #1779

Closed
cilasgimenez opened this issue Nov 3, 2016 · 4 comments
Closed

Problem with Formatter #1779

cilasgimenez opened this issue Nov 3, 2016 · 4 comments

Comments

@cilasgimenez
Copy link

Hi there! I'm facing this issue to format the value printed inside of my Pie Chart and i wasn't able to figure out how to do this:

My chart is printing the values with decimal points but i need Int instead.
I call the func setChart(dataPoints: [String], values: [Double]) with an converted Int to Double for de values. It works, but a want to get rid of the decimal chars. I now it must be done with a formater, so i found this in the PieChartViewController.m demo.

       NSNumberFormatter *pFormatter = [[NSNumberFormatter alloc] init];
    pFormatter.numberStyle = NSNumberFormatterPercentStyle;
    pFormatter.maximumFractionDigits = 1;
    pFormatter.multiplier = @1.f;
    pFormatter.percentSymbol = @" %";
    [data setValueFormatter:[[ChartDefaultValueFormatter alloc] initWithFormatter:pFormatter]];

This is all i needed so i tried to replicate this converting to swift 3 since it's Obj-C and changing the numberStyle. Everything doing fine til i reach the last line. The newest dataset takes an IVALUEFORMATTER instead of NSNUMBER. How do i set this Chart's IVALUEFORMATTER since its don't have the properties like NSNUMBER?

I'll be glad for any help!

@patreu22
Copy link

patreu22 commented Nov 3, 2016

Not sure how it is in Objective-C, but in Swift you can use axis.valueFormatter = DefaultAxisValueFormatter(formatter: myNumberFormatter)

@cilasgimenez
Copy link
Author

cilasgimenez commented Nov 3, 2016

Thanks patreu22.... I tried this:

    let pFormatter = NumberFormatter()
    pFormatter.numberStyle = .none
    MyChart.xAxis.valueFormatter = DefaultAxisValueFormatter(formatter: pFormatter)

But.... fatal error: PieChart has no XAxis:

By the way...i'm using swift 3... the demo code is in obj-c(i don't know why its not updated).

@patreu22
Copy link

patreu22 commented Nov 3, 2016

Sorry, I overread the things about Objective-C haha.

Does pieChart.data?.setValueFormatter(DefaultValueFormatter(formatter: pFormatter)) work for you?

@cilasgimenez
Copy link
Author

Perfect, patreu22.

Thanks so much!

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

2 participants