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

How to add “%” to data in ios-chart #1797

Closed
OuSS-90 opened this issue Nov 6, 2016 · 3 comments
Closed

How to add “%” to data in ios-chart #1797

OuSS-90 opened this issue Nov 6, 2016 · 3 comments

Comments

@OuSS-90
Copy link

OuSS-90 commented Nov 6, 2016

private func setChart(pieChartView: PieChartView, values: [Double]) {

    var dataEntries: [ChartDataEntry] = []

    let dataPoints = ["Apr","May","July"]

    for i in 0..<dataPoints.count {
        let dataEntry = PieChartDataEntry(value: values[i], label: dataPoints[i])
        dataEntries.append(dataEntry)
    }

    let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "")
    pieChartDataSet.colors = [UIColor(red: 17/255, green: 128/255, blue: 127/255, alpha: 1.0),UIColor(red: 47/255, green: 164/255, blue: 59/255, alpha: 1.0),UIColor.orange]
    let pieChartData = PieChartData(dataSet: pieChartDataSet)
    pieChartView.data = pieChartData
    pieChartView.centerText = "Amount Spent"
    pieChartView.chartDescription?.text = ""
    pieChartView.usePercentValuesEnabled = true
    pieChartView.legend.horizontalAlignment = .center

}

screen shot 2016-11-06 at 5 42 07 pm

How to add "%" in PieChart data ? NSNumberFormatter() is no longer available

@OuSS-90 OuSS-90 changed the title Legend text not displayed in iOS-Chart Legend text not displayed Nov 6, 2016
@OuSS-90 OuSS-90 changed the title Legend text not displayed How to add “%” to data in ios-chart Nov 6, 2016
@liuxuan30
Copy link
Member

liuxuan30 commented Nov 7, 2016

use valueFormatter! Please take a look at ChartsDemo first before asking, as it's all there!

    PieChartData *data = [[PieChartData alloc] initWithDataSet:dataSet];

    NSNumberFormatter *pFormatter = [[NSNumberFormatter alloc] init];
    pFormatter.numberStyle = NSNumberFormatterPercentStyle;
    pFormatter.maximumFractionDigits = 1;
    pFormatter.multiplier = @1.f;
    pFormatter.percentSymbol = @" %";
    [data setValueFormatter:[[ChartDefaultValueFormatter alloc] initWithFormatter:pFormatter]];
    [data setValueFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:11.f]];
    [data setValueTextColor:UIColor.whiteColor];

@OuSS-90
Copy link
Author

OuSS-90 commented Nov 7, 2016

Thanks it work now

@RahuliOS88
Copy link

RahuliOS88 commented Dec 28, 2016

How can i set text like this?
screen shot 2016-12-28 at 6 31 31 pm

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