【问题标题】:Charts.js is automatically adding comma as thousands separator when it shouldn'tCharts.js 在不应该时自动添加逗号作为千位分隔符
【发布时间】:2021-11-06 12:34:31
【问题描述】:

Charts.js 滥用在千位之间添加逗号分隔符,而没有设置这样做。给所有的花车。到轴、标签、工具提示,在所有可能的地方和所有类型的图表上。

我在欧盟,所以计算机、浏览器、语言环境与 EN/US 无关。代码中没有指定将这些逗号添加到数字中。 基础数据也不包含逗号:

[{continent:"Africa",value:14802.32},{continent:"Asia",value:6783.37},...]

这很烦人,我的(法国)客户无法接受。

这是一个错误吗?或者请善待并提供如何在任何地方删除逗号的方法。

【问题讨论】:

    标签: chart.js number-formatting comma separator


    【解决方案1】:

    你一定是做错了什么,因为默认情况下数据是用点分隔的,所以你一定是在某个地方指定了它。但您可以使用locale 属性对其进行配置:

    var options = {
      type: 'line',
      data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
          label: '# of Votes',
          data: [12000.5, 19000, 3000, 5000, 2000, 3000],
          borderColor: 'pink'
        }]
      },
      options: {
        //locale: 'en-EN' // Uncomment this line for "wrong" options
      }
    }
    
    var ctx = document.getElementById('chartJSContainer').getContext('2d');
    new Chart(ctx, options);
    <body>
      <canvas id="chartJSContainer" width="600" height="400"></canvas>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.js"></script>
    </body>

    【讨论】:

    • 谢谢,@LeeLenalee。我刚刚设置了语言环境:'fr',逗号消失了。 :D
    • 相当不错!也为我工作。谢谢 LeeLenalee。
    猜你喜欢
    • 1970-01-01
    • 2013-07-20
    • 2012-11-17
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多