echarts数据添加分隔符

export function numberToCurrencyNo(value) {
  if (!value) return 0
    const intPart = Math.trunc(value)
    const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
    let floatPart = ''
    const valueArray = value.toString().split('.')
  if (valueArray.length === 2) {
    floatPart = valueArray[1].toString()
    return intPartFormat + '.' + floatPart
  }
    return intPartFormat + floatPart
}

上述代码为添加分隔符的代码

  series: [
    {
      type: "bar",
      data: [],
      label: {
        formatter: function (p) {
          return numberToCurrencyNo(p.value);
        },
        show: true,
        position: "insideLeft",
      },
      
    },
  ],

label formatter 写方法

要return 

你可能感兴趣的:(echarts,javascript,前端)