show data labels as relative value in percentage on hover - Javascript highcharts

Javascript examples for highcharts:Chart Label

Description

show data labels as relative value in percentage on hover

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() {/*www.  j  av a  2 s .  com*/
  var startingData = [
      [1, '1'],
      [2, '2'],
      [3, '3']
    ],
    percentData = [
      [
        [1, 'x 100%'],
        [2, '200%'],
        [3, '300%']
      ],
      [
        [1, '50%'],
        [2, 'x 100%'],
        [3, '150%']
      ],
      [
        [1, '33%'],
        [2, '66%'],
        [3, 'x 100%']
      ]
    ];
  $('#container').highcharts({
    series: [{
      type: 'bar',
      dataLabels: {
        enabled: true,
        inside: true,
        align: 'right',
        x: -5,
        format: '{point.label}'
      },
      data: $.extend([], startingData),
      keys: ['y', 'label'],
      point: {
        events: {
          mouseOver: function() {
            this.series.setData(percentData[this.x]);
          },
          mouseOut: function() {
            this.series.setData(startingData);
          }
        }
      }
    }]
  });
});

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

Related Tutorials