Hide tooltip for zero value using 'split: true' - Javascript highcharts

Javascript examples for highcharts:Chart Tooltip

Description

Hide tooltip for zero value using 'split: true'

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.js"></script> 
      <style id="compiled-css" type="text/css">

#container {//  w  w w  . ja  va 2  s . c o  m
   max-width: 800px;
   height: 400px;
   margin: 1em auto;
}


      </style> 
      <script type="text/javascript">
$(function() {
  Highcharts.wrap(Highcharts.Tooltip.prototype, 'renderSplit', function (p, labels, points) {
    var i = 0, len = points.length, point, label, modified = false;
    for (; i < len; i++) {
      if (points[i].y === 0) {
        point = points.splice(i, 1)[0];
        label = labels.splice(i + 1, 1)[0];
        modified = true;
        break;
      }
    }
    p.call(this, labels, points);
    if (modified) {
      points.splice(i, 0, point);
      labels.splice(i + 1, 0, label);
    }
  });
  // Create the chart
  Highcharts.chart('container', {
    chart: {
      renderTo: 'container',
      type: 'line'
    },
    title: {
      text: 'Monthly Average Temperature'
    },
    xAxis: {
      categories: ['aa', 'bb', 'cc']
    },
    yAxis: {
      title: {
        text: 'Infor'
      },
      min: - 2
    },
    tooltip: {
      split: true
    },
    plotOptions: {
      line: {
        dataLabels: {
          enabled: true
        }
      }
    },
    series: [{
      name: 'a',
      data: [1, 0, 2]
    }, {
      name: 'b',
      data: [0, 3, 5]
    }]
  });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container"></div>  
   </body>
</html>

Related Tutorials