我正在尝试将巴西货币添加为图表内的数字格式(12345.432 = > R$12.345,43)。 我已将 registerValue 添加到 setupFormatters 中,并将选项添加到controls.jsx 内的 D3_FORMAT_OPTIONS 列表中,但它没有出现在超集中。我还有什么遗漏的吗?
下面有代码显示我所做的事情
内部superset-frontend/src/setup/setupFormatters.ts
.registerValue(
'CURRENCY_BRAZIL',
createD3NumberFormatter({
locale: {
decimal: ',',
thousands: '.',
grouping: [3],
currency: ['R$', ''],
},
formatString: '$,.2f',
}),
)
内部superset-frontend/src/explore/controls.jsx
export const D3_FORMAT_OPTIONS = [
['SMART_NUMBER', 'Adaptative formating'],
['~g', 'Original value'],
[',d', ',d (12345.432 => 12,345)'],
['.1s', '.1s (12345.432 => 10k)'],
['.3s', '.3s (12345.432 => 12.3k)'],
[',.1%', ',.1% (12345.432 => 1,234,543.2%)'],
['.3%', '.3% (12345.432 => 1234543.200%)'],
['.4r', '.4r (12345.432 => 12350)'],
[',.3f', ',.3f (12345.432 => 12,345.432)'],
['+,', '+, (12345.432 => +12,345.432)'],
['$,.2f', '$,.2f (12345.432 => $12,345.43)'],
['CURRENCY_BRAZIL', 'Brazilian Real Currency (12345.432 => R$12.345,43)'],
['DURATION_SUB', 'Duration in ms (100.40008 => 100ms 400µs 80ns)'],
['DURATION', 'Duration in ms (66000 => 1m 6s)'],
];
我还联系了 apache superset slack,我收到了以下答案:
我目前正在尝试添加欧洲货币(欧元),并遇到了这个问题。我似乎已经在我的开发部署中解决了这个问题。 我添加了您提到的相同修改,但不是文件“superset-frontend/src/explore/controls.jsx”,而是修改了“superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting” .ts”
但它实际上并没有解决我的问题,因为我的项目中不存在文件“superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts”。 (我们在项目中使用的是超集版本1.0.0)
转到位于 \superset_env\lib\python3.10\site-packages\superset 的 config.py 文件,并在第 389 行替换为 D3_FORMAT: D3Format = { “十进制”:“,”, "千": ".", “分组”:[3], “货币”:[“R$”,“”]}