前端随手记

导航

echarts数据显示千分位格式

  有时候遇到echarts图表数据需要显示千分位的格式。
--------------------------------------直接上代码-----------------------------------------
 
1.定义转换方法
formatNum(value) {
      if (!value && value !== 0) return 0;

      let str = value.toString();
      let reg =
        str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
      return str.replace(reg, "$1,");
    },
 
 
2.调用方法
label: {
              normal: {
                formatter: function(p){
                  return that.formatNum(p.value) 
                },
              },
            },

posted on 2020-10-16 16:30  前端老表  阅读(4841)  评论(0编辑  收藏  举报