简体   繁体   中英

How to set Strings alongwith Y-axis numbers in ios charts swift

I am searching for the method to add label or string with "ios charts graph",

I want the y-axis to be shown as time with "min" string with it (for eg. 23 min, 24 min and so on)

I found every method was for the x-axis and using numberformatter() but not for the y-axis.

need help to show strings with numbers (double) as in the example I gave above

@MichaelV suggested a good start for you. Just use custom value formatter for YAxis as you used it for XAxis. In fact, XAxis and YAxis classes have the same ancestor.

So you need to declare a value formatter class:

class YAxisValueFormatter: IAxisValueFormatter {
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        return String(value) + " min"
    }
} 

And then set this formatter for left and right axes in your chart:

myChart.leftAxis.valueFormatter = YAxisValueFormatter()
myChart.rightAxis.valueFormatter = YAxisValueFormatter()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM