echart 自定义 formatter
formatter: function(params) { var relVal = [params[0].name]; for (var i=0;i<params.length;i++){ relVal += '\n' + params[i].seriesName+' ' + params[i].value+'%' } return relVal }
params参数可以console.log(params)查看。
tooltip:{ trigger: 'axis', //item axisPointer: { type: 'shadow', }, formatter: '{a0}:{c0}' }
formatter控制显示字数:
axisLabel : { formatter : function (value) { let valueTxt = ''; if (value.length > 3) { valueTxt = value.substring(0, 4) + '...'; } else { valueTxt = value; } return valueTxt ; } }
传入最近七天的日期:
getDateList(count,lang) { var time = new Date().setMinutes(0); time = time - 24*60*60*1000; var categoryData = []; for (var i = 0; i<=count; i++) { categoryData.push(moment(time).format('YYYY-MM-DD')); time += lang; } return categoryData; }
调用getDateList(7,24*60*60*1000),得到如下最近七天日期年月日格式化的数组:
['2021-04-01','2021-04-02','2021-04-03','2021-04-04','2021-04-05','2021-04-06','2021-04-07']