Format Highcharts y-axis labels - Javascript highcharts

Javascript examples for highcharts:Chart Label

Description

Format Highcharts y-axis labels

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 w  w w  . ja v  a  2 s . c o  m*/
    $('#container').highcharts({
        yAxis: {
            labels: {
                formatter: function() {
                    var ret,
                        numericSymbols = ['k', 'M', 'G', 'T', 'P', 'E'],
                        i = 6;
                    if(this.value >=1000) {
                        while (i-- && ret === undefined) {
                            multi = Math.pow(1000, i + 1);
                            if (this.value >= multi && numericSymbols[i] !== null) {
                                ret = (this.value / multi) + numericSymbols[i];
                            }
                        }
                    }
                    return '$' + (ret ? ret : this.value);
                }
            }
        },
        series: [{
            data: [15000, 20000, 30000]
        }]
    });
});

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

Related Tutorials