How to hide highChart plotLine label until mouseov

2019-02-26 00:50发布

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

enter image description here

I have a plotline series on my highChart which has a label. What I'm trying to do is hide the label until mouseover. Has anyone attempted this before?

$(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条回答
走好不送
2楼-- · 2019-02-26 01:11

Use display instead of 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

查看更多
登录 后发表回答