Y value minus 1 in tooltip - Javascript highcharts

Javascript examples for highcharts:Chart Tooltip

Description

Y value minus 1 in tooltip

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts - difference in tooltip</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//w  w  w.  j a v a  2  s  .co m
Highcharts.chart('container', {
    title: {
            text: 'Testing HighCharts'
    },
    data: {
            csv: document.getElementById('csv').innerHTML
    },
    rangeSelector: {
        selected: 1
    },
    tooltip: {
        formatter:function(){
            var diffText = '',
                i = this.point.index;
            if (i > 0) {
                diffText = '<br><b>Difference: </b>' + (this.y - this.point.series.data[i-1].y);
            }
            return '<b>Date:</b> ' + Highcharts.dateFormat('%B %e %Y', this.x) + '<br>' + '<b>Amount:</b> ' + this.y + '<br>' + diffText;
        }
    },
    plotOptions: {
        series: {
            marker: {
                enabled: true,
                fillColor: 'FFFFFF',
                radius: 4
            },
            allowPointSelect: true,
            color: '#CC0000',
            width: 3
        }
    }
});
    }

      </script> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/data.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> 
      <pre id="csv" style="display:none">Year
2017-05-12,150,
2017-06-10,175,
2017-07-16,215,
2017-08-14,280,
2017-09-14,395,</pre>  
   </body>
</html>

Related Tutorials