Javascript 当用户离开图表区域时,删除同步图表中的工具提示

Javascript 当用户离开图表区域时,删除同步图表中的工具提示,javascript,jquery,charts,highcharts,Javascript,Jquery,Charts,Highcharts,我正在使用同步海图来演示统计数据。 供参考: 在这里,第一次绘制图表时,未选择任何数据点。当光标进入图表区域时,工具提示、十字光标和数据点将高亮显示。它按预期工作 我需要的修改是,当用户从图表中出来时,图表应该与加载阶段一样 i、 e.如果光标不在任何图表上,则不应选择任何数据点。换句话说,应该删除数据点上的工具提示、十字线和高亮显示的阴影 提前感谢您的帮助或建议。使用mouseleave检测鼠标何时离开容器: $('#container').bind('mouseleave', functio

我正在使用同步海图来演示统计数据。 供参考:

在这里,第一次绘制图表时,未选择任何数据点。当光标进入图表区域时,工具提示、十字光标和数据点将高亮显示。它按预期工作

我需要的修改是,当用户从图表中出来时,图表应该与加载阶段一样

i、 e.如果光标不在任何图表上,则不应选择任何数据点。换句话说,应该删除数据点上的工具提示、十字线和高亮显示的阴影


提前感谢您的帮助或建议。

使用mouseleave检测鼠标何时离开容器:

$('#container').bind('mouseleave', function(e) {
使用“隐藏方法”隐藏工具提示,使用“隐藏十字线”方法隐藏十字线:

  chart.tooltip.hide(point);
  chart.xAxis[0].hideCrosshair();  
检查示例():

$(函数(){
$(“#容器”).bind('mouseleave',函数(e){
var图,
指向
我
事件
对于(i=0;i
我不知道为什么,但对我来说,它在离开图表时不会删除悬停点。
$(function() {


  $('#container').bind('mouseleave', function(e) {
    var chart,
      point,
      i,
      event;

    for (i = 0; i < Highcharts.charts.length; i = i + 1) {
      chart = Highcharts.charts[i];
      event = chart.pointer.normalize(e.originalEvent);
      point = chart.series[0].searchPoint(event, true);

      point.onMouseOut(); 
      chart.tooltip.hide(point);
      chart.xAxis[0].hideCrosshair(); 
    }
  });
  $('#container').bind('mousemove touchmove touchstart', function(e) {
    var chart,
      point,
      i,
      event;

    for (i = 0; i < Highcharts.charts.length; i = i + 1) {
      chart = Highcharts.charts[i];
      event = chart.pointer.normalize(e.originalEvent); // Find coordinates within the chart
      point = chart.series[0].searchPoint(event, true); // Get the hovered point

      if (point) {
        point.onMouseOver(); // Show the hover marker
        chart.tooltip.refresh(point); // Show the tooltip
        chart.xAxis[0].drawCrosshair(event, point); // Show the crosshair
      }
    }
  });
  /**
   * Override the reset function, we don't need to hide the tooltips and crosshairs.
   */
  Highcharts.Pointer.prototype.reset = function() {
    return undefined;
  };

  /**
   * Synchronize zooming through the setExtremes event handler.
   */
  function syncExtremes(e) {
    var thisChart = this.chart;

    if (e.trigger !== 'syncExtremes') { // Prevent feedback loop
      Highcharts.each(Highcharts.charts, function(chart) {
        if (chart !== thisChart) {
          if (chart.xAxis[0].setExtremes) { // It is null while updating
            chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {
              trigger: 'syncExtremes'
            });
          }
        }
      });
    }
  }

  // Get the data. The contents of the data file can be viewed at
  // https://github.com/highcharts/highcharts/blob/master/samples/data/activity.json
  $.getJSON('https://www.highcharts.com/samples/data/jsonp.php?filename=activity.json&callback=?', function(activity) {
    $.each(activity.datasets, function(i, dataset) {

      // Add X values
      dataset.data = Highcharts.map(dataset.data, function(val, j) {
        return [activity.xData[j], val];
      });

      $('<div class="chart">')
        .appendTo('#container')
        .highcharts({
          chart: {
            marginLeft: 40, // Keep all charts left aligned
            spacingTop: 20,
            spacingBottom: 20
          },
          title: {
            text: dataset.name,
            align: 'left',
            margin: 0,
            x: 30
          },
          credits: {
            enabled: false
          },
          legend: {
            enabled: false
          },
          xAxis: {
            crosshair: true,
            events: {
              setExtremes: syncExtremes
            },
            labels: {
              format: '{value} km'
            }
          },
          yAxis: {
            title: {
              text: null
            }
          },
          tooltip: {
            positioner: function() {
              return {
                x: this.chart.chartWidth - this.label.width, // right aligned
                y: -1 // align to title
              };
            },
            borderWidth: 0,
            backgroundColor: 'none',
            pointFormat: '{point.y}',
            headerFormat: '',
            shadow: false,
            style: {
              fontSize: '18px'
            },
            valueDecimals: dataset.valueDecimals
          },
          series: [{
            data: dataset.data,
            name: dataset.name,
            type: dataset.type,
            color: Highcharts.getOptions().colors[i],
            fillOpacity: 0.3,
            tooltip: {
              valueSuffix: ' ' + dataset.unit
            }
          }]
        });
    });
  });
});