show decimal places only if needed for line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

show decimal places only if needed for line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <div id="container"></div> 
      <script type="text/javascript">
Highcharts.chart('container', {
  yAxis: {//from  w w  w . j a  va  2  s.  com
    tickInterval: 1.25,
    labels: {
      formatter: function() {
        var value = this.value;
        if (value % 1) {
          return Highcharts.numberFormat(value, 2);
        }
        return value;
      }
    }
  },
  series: [{
    data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
  }, {
    data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
  }]
});

      </script>  
   </body>
</html>

Related Tutorials