首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在第一列中不能设置值的格式

在第一列中不能设置值的格式
EN

Stack Overflow用户
提问于 2021-12-19 18:34:12
回答 1查看 58关注 0票数 0

我正在尝试配置以下代码,以便将PROFIT列(这是第一个列)格式化为货币。

在这里,您有一个JSFiddle,下面的代码在代码片段中不起作用:

https://jsfiddle.net/tlg265/eo1bkjwy/

现在,该列中的值显示为:

代码语言:javascript
复制
1243898
1538192
1921982

但我想让他们看到:

代码语言:javascript
复制
$1,243,898
$1,538,192
$1,921,982

这里有个预览..。

下面是代码,您可以看到我引入了一种新的格式:currency,我试图在第一栏:PROFIT中使用它,但没有成功。

代码语言:javascript
复制
$(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",
          },
        ],
      },
    },
  });
});
代码语言:javascript
复制
<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>

你知道我该怎么做吗?

EN

回答 1

Stack Overflow用户

发布于 2021-12-19 19:14:38

我在柔性版的文档中找不到方法,所以我做了自己的

https://jsfiddle.net/mplungjan/acuk3vjn/

代码语言:javascript
复制
const fmt = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })

data: [......].map(({Profit,Following,Followers}) => ({Profit:`${fmt.format(Profit)}`,Following,Followers})),

我还将货币添加到其他列中。

代码语言:javascript
复制
formats: [
  {
    name: "",
    thousandsSeparator: ",",
    decimalSeparator: ".",
    decimalPlaces: -1,
    maxDecimalPlaces: -1,
    maxSymbols: 20,
    currencySymbol: "$",

给出结果.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70414280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档