Open sahruday opened 4 years ago
you can custom like this
class ChartNumberFormat : ValueFormatter() {
override fun getFormattedValue(
value: Float
): String {
// Menggunakan long untuk angka yang lebih besar dari int
val trillion = 1000000000000L // Miliaran
val billion = 1000000000L // Miliaran
val million = 1000000L // Juta
val thousand = 1000L // Ribu
return if (value >= trillion) {
String.format(Locale("in", "ID"), "%.2f T", value / trillion) // Format untuk trillion
} else if (value >= billion) {
String.format(Locale("in", "ID"), "%.1f B", value / billion) // Format untuk miliaran
} else if (value >= million) {
String.format(Locale("in", "ID"), "%.0f M", value / million) // Format untuk juta
} else if (value >= thousand) {
String.format(Locale("in", "ID"), "%.0f K", value / thousand) // Format untuk ribuan
} else {
value.toInt().toString() // Format untuk angka di bawah ribuan
}
}
}
and add ChartNumberFormat to valueFormatter
val leftAxis: YAxis = chart.axisLeft
leftAxis.textSize = 12f
leftAxis.valueFormatter = ChartNumberFormat()
leftAxis.axisMinimum = 0f // this replaces setStartAtZero(true)
leftAxis.textColor = getColor(requireActivity(), R.color.black_color)
leftAxis.granularity = 1.0f
leftAxis.isGranularityEnabled = true
@PhilJay can you look into it. For value formatting, we use Decimal Formatter with a pattern, and symbols are not added.
Solution: Add Symbols parameter using DecimalFormatSymbols. or add an extra parameter to add by the user.
Solution : Replace regex can be changed to "[E|e][0-9][0-9]". If this is used then the Language Change Cannot be done as we get the regex in the other language formats.