[Small program] Using the echarts tooltip on the small program does not display the data of the x-axis, and the custom tooltip display

Using the echarts tooltip on the applet does not display the data of the x-axis

Then go to customize the display of the tooltip!

Applet:
Attention! For small programs, use line break here: '\n'

tooltip: {
    
    
  trigger: 'axis',
  // 这里自定义只是为了把x轴的数据也显示出来
  formatter:function(datas) {
    
    
    let res = datas[0].name;
    for (const i in datas){
    
    
      res += '\n' + datas[i].seriesName + ':' + datas[i].value
    }
    return res
  }
},

insert image description here


PC and H5, etc.:

tooltip: {
    
    
  trigger: 'axis',
  // 这里自定义给数值保留两位小数点、加单位
  formatter:function(datas) {
    
    
    let res = datas[0].name + '<br/>';
    for (const i in datas){
    
    
      let dw = datas[i].seriesName === '数量' ? '个':'元';
      let val = datas[i].value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
      res += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' + datas[i].color + ';"></span>' + datas[i].seriesName + ':' + val + dw + '<br/>'
    }
    return res
  }
},

insert image description here

Guess you like

Origin blog.csdn.net/LuviaWu/article/details/122706244
Recommended