ChartJS 垂直线未在 touchend 上删除

ubi*_*bik 5 javascript touch chart.js

我使用这个插件在用户触摸/悬停在图表上的位置绘制一条垂直线:

Chart.plugins.register({
   afterDatasetsDraw: function(chart) {
      if (chart.tooltip._active && chart.tooltip._active.length) {
         var activePoint = chart.tooltip._active[0],
            ctx = chart.ctx,
            y_axis = chart.scales['y-axis-0'],
            x = activePoint.tooltipPosition().x,
            topY = y_axis.top,
            bottomY = y_axis.bottom;
         ctx.save();
         ctx.beginPath();
         ctx.moveTo(x, topY);
         ctx.lineTo(x, bottomY);
         ctx.lineWidth = 1;
         ctx.strokeStyle = '#26D4A5';
         ctx.stroke();
         ctx.restore();
      }
   }
});
Run Code Online (Sandbox Code Playgroud)

悬停结束后,该线会被删除,但是如果发生 touchend/touchcancel,该线仍然存在。

我尝试将 afterEvent 添加到插件中,如下所示:

Chart.plugins.register({
   afterDatasetsDraw: function(chart) {
      if (chart.tooltip._active && chart.tooltip._active.length) {
         var activePoint = chart.tooltip._active[0],
            ctx = chart.ctx,
            y_axis = chart.scales['y-axis-0'],
            x = activePoint.tooltipPosition().x,
            topY = y_axis.top,
            bottomY = y_axis.bottom;
         ctx.save();
         ctx.beginPath();
         ctx.moveTo(x, topY);
         ctx.lineTo(x, bottomY);
         ctx.lineWidth = 1;
         ctx.strokeStyle = '#26D4A5';
         ctx.stroke();
         ctx.restore();
      }
   },
   afterEvent: function(chart, e) {
     if(e.type=="mouseout"){
       alert("mouseout");
     }
     if(e.type=="touchend"){
       alert("touchend");
     }
     if(e.type=="mousemove"){
       alert("mouse move");
     }
   }
});
Run Code Online (Sandbox Code Playgroud)

但唯一适用于触摸的事件是 mousemove、touchend 和 mouseout,不适用于 mobile/touch。有什么解决方法吗?

ubi*_*bik 3

似乎问题是“touchend”事件已从默认配置中删除。

将事件“touchend”重新添加到类似这样的选项中,会删除 touchend 后的工具提示。

events: ["mousemove", "mouseout", "click", "touchstart", "touchmove", "touchend"]
Run Code Online (Sandbox Code Playgroud)

此处更改: https: //github.com/chartjs/Chart.js/pull/1644/files