Question: I can't find out how to change the text gravity of the right side labels of my MPAndroidChart.

[That's how it looks actual](https://i.stack.imgur.com/raQbi.png) [![enter image description here](https://i.stack.imgur.com/Rksnn.png)](https://i.stack.imgur.com/Rksnn.png)

[This is what it should look like](https://i.stack.imgur.com/5ngeb.png)[![enter image description here](https://i.stack.imgur.com/e7jQW.png)](https://i.stack.imgur.com/e7jQW.png)

How is that to be done?

Answer: 
You can generalize your `getEnumFromString` function by creating an interface and having your companion object implementing it. An extension on this interface will let you call the function directly on the companion of your enum class.

This will do the trick:

```
interface EnumWithKey<T : Enum<T>, K> {
    val T.key: K
}

/* The reified type parameter lets you call the function without explicitly 
 * passing the Class-object.
 */
inline fun <reified T : Enum<T>, K> EnumWithKey<T, K>.getByKey(key: K): T? {
    return enumValues<T>().find { it.key == key }
}

```

Now you can create your `PaymentMethodType` like this:

```
enum class PaymentMethodType(val type: String) {
    PAYPAL("Paypal"),
    VISA("Visa"),
    MASTERCARD("MasterCard"),
    VISA_DEBIT("VISA Debit"),
    LPQ_CREDIT("Lpq Credit");

    companion object : EnumWithKey<PaymentMethodType, String> {
        // Just define what the key is
        override val PaymentMethodType.key
            get() = type
    }
}

```

And voila, now you can do this:

```
println(PaymentMethodType.getByKey("Paypal")) // Prints PAYPAL

```

The `EnumWithKey` interface can now be reused by just having the companion object of an enum implementing it.
Get all enum values with `PaymentMethodType.values()`, then use `find()` to get the one you need: 

```
fun fromString(type: String): PaymentMethodType? = PaymentMethodType.values().find { it.type.toLowerCase() == type.toLowerCase() }

```