Display a tooltip for two points with exactly the same time - Javascript highcharts

Javascript examples for highcharts:Chart Tooltip

Description

Display a tooltip for two points with exactly the same time

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
$(function () {//from   w  w  w  .ja v  a2s.c o  m
    $('#container').highcharts({
        chart: {
            type: 'spline'
        },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: {
                month: '%e. %b',
                year: '%b'
            },
            title: {
                text: 'Date'
            }
        },
        yAxis: {
            title: {
                text: 'Snow depth (m)'
            },
            min: 0
        },
        tooltip: {
            formatter:function(){
                var x = this.x,
                    series = this.series,
                    txt = '<b>'+series.name+'</b><br>';
                $.each(series.data, function(i,p){
                    if(p.x === x) {
                        txt += Highcharts.dateFormat('%e. %b',p.x) + ': ' + p.y + ' m <br/>';
                    }
                });
                return txt;
            },
        },
        plotOptions: {
            spline: {
                marker: {
                    enabled: true
                }
            }
        },
        series: [{
            name: 'Winter 2007-2008',
            data: [
                [Date.UTC(1970,  9, 27), 0   ],
                [Date.UTC(1970, 10, 10), 0.6 ],
                [Date.UTC(1970, 10, 18), 0.7 ],
                [Date.UTC(1970, 11,  2), 0.8 ],
                [Date.UTC(1970, 11,  2), 0.2 ],
                [Date.UTC(1970, 11,  9), 0.6 ]
            ]
        }]
    });
});

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>  
   </body>
</html>

Related Tutorials