Date and number format - Javascript highcharts

Javascript examples for highcharts:Chart Configuration

Description

Date and number format

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

#container {// ww w  .j  av a  2 s  . c  om
   min-width: 310px;
   max-width: 800px;
   height: 400px;
   margin: 0 auto
}


      </style> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/modules/series-label.js"></script> 
      <script src="https://code.highcharts.com/modules/exporting.js"></script> 
      <div id="container"></div> 
      <script type="text/javascript">
Highcharts.chart('container', {
  chart: {
    type: 'column'
  },
  title: {
    text: 'Time Worked per Day'
  },
  xAxis: {
    type: 'category'
  },
  yAxis: {
    labels: {
      formatter: function() {
        if (this.y < 0) {
          return Highcharts.numberFormat(this.value / 3600000, 0);
        } else {
          return Highcharts.numberFormat(this.value / 3600000, 0);
        }
      }
    },
    title: {
      text: 'Hours'
    },
    tickInterval: 3600000
  },
  credits: {
    enabled: false
  },
  legend: {
    enabled: false
  },
  plotOptions: {
    series: {
      borderWidth: 0,
      dataLabels: {
        enabled: true,
        formatter: function() {
          if (this.y < 0) {
            return Highcharts.dateFormat('-%Hh%M', new Date(Math.abs(this.y)));
          } else {
            return Highcharts.dateFormat('%Hh%M', new Date(this.y));
          }
        }
      }
    }
  },
  tooltip: {
    formatter: function() {
      if (this.y < 0) {
        return '<b>' + this.series.name + ' : </b>' +
          Highcharts.numberFormat(this.y / 3600000, 2);
      } else {
        return '<b>' + this.series.name + ' : </b>' +
          Highcharts.numberFormat(this.y / 3600000, 2);
      }
    }
  },
  series: [{
    name: 'Hours',
    colorByPoint: true,
    data: [
      ["23-05-16", 9000000],
      ["24-05-16", 7000000],
      ["25-05-16", 9000000],
      ["26-05-16", 7000000],
      ["27-05-16", 8000000],
      ["28-05-16", -9000000],
      ["29-05-16", 7000000],
      ["30-05-16", 8000000],
      ["01-06-16", 8000000],
      ["02-06-16", 8000000]
    ]
  }]
});

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

Related Tutorials