Shared Tooltip for multi-axes chart with positioning in column chart and line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

Shared Tooltip for multi-axes chart with positioning in column chart and line chart

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://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
      <script type="text/javascript">
$(function() {/*from  ww w  .j a  v a  2  s  .  co m*/
  $('#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.highlight(e);
      }
    }
  });
  Highcharts.Pointer.prototype.reset = function() {
    return undefined;
  };
  Highcharts.Point.prototype.highlight = function(event) {
    this.onMouseOver(); // Show the hover marker
    this.series.chart.tooltip.refresh(this); // Show the tooltip
    this.series.chart.xAxis[0].drawCrosshair(event, this); // Show the crosshair
  };
  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'
            });
          }
        }
      });
    }
  }
  var dataset = [{
    "name": "Series 1",
    "type": "column",
    "data": [29.9, 71.5, 106.4]
  }, {
    "name": "Series 2",
    "type": "line",
    "data": [216.4, 194.1, 95.6]
  }];
  for (var i = 0; i < dataset.length; i++) {
    var dataitem = dataset[i];
    $("<div class=\"chart\">")
      .appendTo('#container').highcharts({
         title: {
           text: dataitem.name
        },
        xAxis: {
          categories: ['Jan', 'Feb', 'Mar']
        },
        tooltip: {
          crosshairs: {
            color: 'rgba(27,161,218,0.5)',
            dashStyle: 'solid',
            zIndex: -1
          }
        },
        series: [{
          data: dataitem.data,
          name: dataitem.name,
          type: dataitem.type
        }]
      });
  };
});

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

Related Tutorials