小程序使用echarts,图表数据多,常现tooltip失去响应,手写touch方法触发tooltip

小程序使用echarts,图表数据多,常现tooltip失去响应,手写touch方法触发tooltip

图表

<ec-canvas id="mychart-dom-line" canvas-id="device-trans-echart" style="display:block" ec="{{ ec }}" bindtouchmove="chartTouch" bindtouchstart="chartTouch" bind:init="echartInit">ec-canvas>

js chartTouch方法

chartTouch: function(e) {
    var one = (this.data.windowWidth / (option.xAxis[0].data.length+2)).toFixed(2); //x轴数据间隔一格的宽度,+2因为grid左右留了大概一格的空隙
    var result = Math.max(Math.min(Math.ceil((e.changedTouches[0].clientX - 50) / one), option.xAxis[0].data.length-1), 0); //经过测试,上面算间隔宽度时候+2,触屏坐标-50与tooltip显示所在视觉较为接近
    if(showTipIndex != result) {
      showTipIndex = result;
      chartDevice.dispatchAction({
        type: 'showTip',
        seriesIndex: 3,
        dataIndex: result
      });
    }
  },

你可能感兴趣的:(微信小程序,小程序,echarts)