如何隐藏highChart plotLine标签直到鼠标悬停?

时间:2016-07-27 15:02:27

标签: javascript charts highcharts

http://jsfiddle.net/leongaban/n36y336z/

enter image description here

我的highChart上有一个带有标签的情节系列。我要做的是隐藏标签直到鼠标悬停。有没有人试过这个?

$(function() {
  var $report = $('#report');

  $('#container').highcharts({
    xAxis: {
      plotLines: [{ // mark the weekend
        color : 'rgba(254,235,236,0.5)',
        from  : Date.UTC(2010, 0, 2),
        to    : Date.UTC(2010, 0, 3),
        zIndex: 1,
        label: {
          text    : 'Event',
          align   : 'left',
          style   : { color: '#000' },
          visible : false
        },
        events: {
          click: function(e) {
              console.log('clicked event')
          },
          mouseover: function(e) {
              console.log('show plotline label')
          },
          mouseout: function(e) {
              console.log('hide plotline label')
          }
        }
      }],
      tickInterval: 24 * 3600 * 1000,
      type: 'datetime'
    },

    series: [{
      data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4],
      pointStart: Date.UTC(2010, 0, 1),
      pointInterval: 24 * 3600 * 1000
    }]
  });
});

1 个答案:

答案 0 :(得分:2)

使用display代替visible

plotLines: [{ // mark the weekend
  label: {
    text: 'label',
    style: {
      display: 'none'
    }
  },
  events: {
    mouseover: function (e) {
      this.label.element.style.display='block';
    },
    mouseout: function (e) {
      this.label.element.style.display='none';
    }
  }
}], 

JSFiddle demo