我正在尝试配置以下代码,以便将PROFIT列(这是第一个列)格式化为货币。
在这里,您有一个JSFiddle,下面的代码在代码片段中不起作用:
https://jsfiddle.net/tlg265/eo1bkjwy/
现在,该列中的值显示为:
1243898
1538192
1921982但我想让他们看到:
$1,243,898
$1,538,192
$1,921,982这里有个预览..。

下面是代码,您可以看到我引入了一种新的格式:currency,我试图在第一栏:PROFIT中使用它,但没有成功。
$(function() {
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: false,
report: {
data: [{
"Profit": "1243898",
"Following": 81,
"Followers": 242,
},
{
"Profit": "1538192",
"Following": 728,
"Followers": 2178,
},
{
"Profit": "1921982",
"Following": 4423,
"Followers": 12387,
},
{
"Profit": "1243898",
"Following": 63,
"Followers": 189,
},
{
"Profit": "1538192",
"Following": 342,
"Followers": 931,
},
{
"Profit": "1538192",
"Following": 487,
"Followers": 1242,
},
{
"Profit": "1921982",
"Following": 3827,
"Followers": 15281,
},
{
"Profit": "1243898",
"Following": 97,
"Followers": 279,
},
{
"Profit": "1538192",
"Following": 242,
"Followers": 728,
},
{
"Profit": "1921982",
"Following": 4921,
"Followers": 12489,
},
{
"Profit": "1243898",
"Following": 69,
"Followers": 182,
},
],
formats: [{
name: "",
thousandsSeparator: " ",
decimalSeparator: ".",
decimalPlaces: -1,
maxDecimalPlaces: -1,
maxSymbols: 20,
currencySymbol: "",
negativeCurrencyFormat: "-$1",
positiveCurrencyFormat: "$1",
isPercent: "false",
nullValue: "",
infinityValue: "Infinity",
divideByZeroValue: "Infinity",
textAlign: "right",
beautifyFloatingPoint: true,
},
{
name: "currency",
currencySymbol: "$",
},
],
slice: {
rows: [{
uniqueName: "Profit",
format: "currency",
}],
columns: [{
uniqueName: "[Measures]",
}],
measures: [{
uniqueName: "Following",
},
{
uniqueName: "Followers",
},
],
},
},
});
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container"></div>
你知道我该怎么做吗?
发布于 2021-12-19 19:14:38
我在柔性版的文档中找不到方法,所以我做了自己的
https://jsfiddle.net/mplungjan/acuk3vjn/
const fmt = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })
data: [......].map(({Profit,Following,Followers}) => ({Profit:`${fmt.format(Profit)}`,Following,Followers})),我还将货币添加到其他列中。
formats: [
{
name: "",
thousandsSeparator: ",",
decimalSeparator: ".",
decimalPlaces: -1,
maxDecimalPlaces: -1,
maxSymbols: 20,
currencySymbol: "$",给出结果.

https://stackoverflow.com/questions/70414280
复制相似问题