3

I am trying to do some customization in the apache superset. I want to show the number in superset chart in the Indian format. For eg. 1

10

100

1,000

10,000

1,00,000

10,00,000

1,00,00,000

10,00,00,000

In the number format dropdown when I am exploring chart there is no option to show the data like this. I have done set up a dev version of superset on my machine and found that it is using a package superset-ui-number-format. Now I don't know how to proceed with that.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Piyush Singhal
  • 330
  • 1
  • 3
  • 8

1 Answers1

3

If you can edit the code for your Superset instance/deployment, there is a way to accomplish this. This assumes you've pulled your code from GitHub, and thus have a superset-frontend folder. If so, then open superset-frontend/src/setup/setupFormatters.js and do the following:

  1. At the top, alongside createDurationFormatter make sure to import createD3NumberFormatter from @superset-ui/number-format

  2. Alongside all the registerValue entries following getNumberFormatterRegistry(), add one more that looks like so:

.registerValue(
  'CURRENCY_INDIA',
  createD3NumberFormatter({
    locale: {
      decimal: '.',
      thousands: ',',
      grouping: [3, 2, 2, 2, 2, 2, 2, 2, 2, 2],
      currency: ['₹', ''],
    },
    formatString: '$,.2f',
  }),
)

Then, when you're editing a chart in the Explore view, you can type CURRENCY_INDIA as your formatter, and it should work!

Indian currency formatter

Optionally, if you're maintaining a fork of superset-ui you can add this as an option included in the Explore viz controls. To do that, you would add it in superset-ui_preset/packages/superset-ui-chart-controls/src/shared-controls/index.tsx as one of the exported D3_FORMAT_OPTIONS.

Evan Rusackas
  • 579
  • 4
  • 6
  • Any plan to raise pull request to the master branch? – Adi Aug 03 '21 at 06:06
  • I hadn't planned to open a PR for this @Adi, as I haven't heard of any other demand for it, and I feared that if I added a formatter for one currency, we probably *should* do it for all the other major currencies... and add some configuration flags for which ones to enable. It just felt like a slippery slope. If you'd like to open a PR, go for it! Or if you're not an engineer and just need it in there, let me know and I can do it. – Evan Rusackas Dec 01 '21 at 02:59