flutterdartnumber-formattingsyncfusionflutter-charts

How to convert T(Thousand) to (K) in Indian Locale for compact currency, in Syncfusion Charts in Flutter


I am using syncfusion charts where I need to display the Y axis in compact format. Syncfusion by default offers a parameter in NumberFormat from intl to allow formatting. But the compact number symbols used in the library is below,

COMPACT_DECIMAL_SHORT_PATTERN: const {
    3: '0T',
    4: '00T',
    5: '0L',
    6: '00L',
    7: '0Cr',
    8: '00Cr',
    9: '000Cr',
    10: '0TCr',
    11: '00TCr',
    12: '0LCr',
    13: '00LCr',
    14: '000LCr',
  }

Here thousand is displayed as T, but I need to convert it to K, I can't directly edit this file where the symbols are entered, because the deployment is happening via a CI/CD pipeline which download its own pub cache on each deployment. I can add a process to replace the symbols file with a modified file as part of the pipeline, but I don't know if it's a good practice, or what problems may arise over that.

I was thinking of including the entire intl inside the lib, and work it out, the task by itself seems too complicated, even if I did, I need to clone and modify the syncfusion also. cuz, as it requires the intl from pub cache.


Solution

  • Numeric Axis constructor has an option to fromat the axis, axisLablelFormatter,

          axisLabelFormatter: (AxisLabelRenderDetails args) {
            NumberFormat numberFormat;
            if (args.value < 100000) {
              numberFormat = NumberFormat.compact();
            } else {
              numberFormat = NumberFormat.compact(locale: "en_IN");
            }
            var text = numberFormat.format(args.value);
            return ChartAxisLabel(text, args.textStyle);
          },