Charts.js 在不应该时自动添加逗号作为千位分隔符 [英] Charts.js is automatically adding comma as thousands separator when it shouldn't

查看:15
本文介绍了Charts.js 在不应该时自动添加逗号作为千位分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Charts.js is abusively adding comma separator between thousands while is nowhere set to do this. To all floats. To the axis, labels, tooltips, everywhere possible and on all types of charts.

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

I am in EU, so the computer, browser, locales have nothing to do with EN/US. Nowhere in the code is specified to add these commas to numbers. The underlying data does not contain commas either:

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

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

This is very annoying, unacceptable for my (French) customer.

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

Is it a bug ? Or please be kind and provide the way how to remove comma everywhere.

推荐答案

你一定做错了,因为默认情况下数据是用点分隔的,所以你一定在某个地方指定了它.但您可以使用 locale 属性:

You must be doing something wrong because by default the data is seperated by dots, so you must have specified it somewhere. But you can configure it by using the locale property:

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>

这篇关于Charts.js 在不应该时自动添加逗号作为千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆