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 show double vale with string in y-axis #3683

Closed
1 task done
EndLess728 opened this issue Oct 9, 2018 · 2 comments
Closed
1 task done

How to show double vale with string in y-axis #3683

EndLess728 opened this issue Oct 9, 2018 · 2 comments

Comments

@EndLess728
Copy link

EndLess728 commented Oct 9, 2018

What did you do?

ℹ NSformatter onlu accespts integer/double values but not string here is my code which i want to modify to show like i want .
for i in 0..<PayoutChart.count {

let value = ChartDataEntry(x: Double(i), y: PayoutChart[i])
lineChartEntry.append(value)
}
// here we add it to the data set

Note :- I am doing it for line chart in ios charts

let line1 = LineChartDataSet(values: lineChartEntry, label: "Payouts") //Here we convert lineChartEntry to a LineChartDataSet
line1.mode = .cubicBezier

ℹ I want to show the values on y axis like 1 min, 2 min , 3 min and so on ..

What happened instead?

ℹ it is showing the values like 1,2,3 and i want the string "min" as a suffix in y-axis values

Charts Environment

Charts version/Branch/Commit Number: 3.2
Xcode version: 10
Swift version: 4.2
Platform(s) running Charts:
macOS version running Xcode: 10.13.6

@mandrusiaks
Copy link

mandrusiaks commented Oct 10, 2018

I've managed to solve this by creating a custom axis formatter and implementing the required stringForValue function.

final class CustomAxisValueFormatter: IAxisValueFormatter {
    ....
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        let yVal = Int(value)
        return "\(yVal) min"
   }
}

This is just an example using integer values on the axis. Will be slightly different if you need double values.

Don't forget to set leftAxis.valueFormatter on your chart to your custom formatter

@EndLess728
Copy link
Author

thanx solved .

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