Format Data Label - Javascript highcharts

Javascript examples for highcharts:Chart Label

Description

Format Data Label

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">
    $(window).load(function(){/*from  w  w  w  .  jav  a2  s  . com*/
$("#container").highcharts({
    xAxis: {
        categories: ['a', 'b', 'c', 'd', 'e', 'f']
    },
    series: [{
        data: [1, 4, 3, 7, 10, 1],
        name: 'Value',
        dataLabels: {
            enabled: true,
            formatter: function () {
                var dataSum = 0;
                console.log(this);
                for (var i = 0; i < this.series.data.length; i++) {
                    dataSum += this.series.data[i].y;
                };
                var pcnt = (this.y / dataSum) * 100;
                return '<b>Value</b>: ' + this.point.y + '<br/>' + '<b>Percent</b>: ' + pcnt + '%';
            }
        }
    }]
});
    });

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

Related Tutorials