I'm using LineChart from Danielgindi/Charts. I have a requirement to display custom text instead of values on x-axis.
With my implementation, I got this

But, I need it as

If you observe in the second image, there is text (WEEK 1, WEEK 2, WEEK 3, WEEK 4) on x-axis instead of values (0.0, 0.8, 1.6, 2.4) as in first image.
Let me know, if there is any option to show the text instead of value on x-axis.
You have to create a class which implements AxisValueFormatter protocol.
The only function you have to implement is func stringForValue(_ value: Double, axis: AxisBase?) -> String
class SomeClass: AxisValueFormatter {
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return weeks[Int(value)]
}
}
var weeks = ["WEEK1", "WEEK2", "WEEK3", "WEEK4"]
chart.xAxis.valueFormatter = SomeClass()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With