show different dates on labels in line chart - Javascript highcharts

Javascript examples for highcharts:Line Chart

Description

show different dates on labels in 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"> 
      <style id="compiled-css" type="text/css">

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


      </style> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script>
       tickInterval: 
      <input id="tick" type="number" value="3"> 
      <div id="container" style="height: 400px"></div> 
      <script type="text/javascript">
var timearray = [];
var time = new Date().valueOf();
var delay = 50 * 60 * 1000; //50 minutes
for (var i=0; i<12; i++) {
  var date = new Date(i * delay + time).toLocaleString('en-us', {day: 'numeric', month: 'short', hour: 'numeric', minute: 'numeric', hour12: false});
  timearray[i] =date;
}
var drawChart = function () {
  Highcharts.chart('container', {
      legend: {
          enabled: false
      },
      xAxis: {
          title: {
              text: 'Date'
          },
          tickmarkPlacement: 'on',
          tickInterval: parseInt(document.getElementById('tick').value),
          categories: timearray
      },
      series: [{
          data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
      }]
  });
};
drawChart();
document.getElementById('tick').addEventListener('change keyup mouseup', drawChart);

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

Related Tutorials