Minimize x axis labels to day hours in chart js for line chart - Javascript Chart.js

Javascript examples for Chart.js:Line Chart

Description

Minimize x axis labels to day hours in chart js for line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.0/Chart.bundle.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*w w w  .  j  a v  a 2 s  .  co  m*/
function newDate() {
  return moment().add(days, 'd');
}
var config = {
  type: 'line',
  data: {
    labels: ['00:00','01:15', '02:00', '03:20', '04:00', '05:00', '06:00','07:00','08:00','09:00','10:00','11:00',
    '12:00','13:00','14:00','15:00','16:00','17:00','18:00','23:59'],
    datasets: [{
      label: "My First dataset",
      data: [1, 3, 4, 2, 1, 4, 2],
    }]
  },
  options: {
    scales: {
      xAxes:[{
  type: 'time',
  time: {
    format: "HH:mm",
    unit: 'hour',
    unitStepSize: 1,
    displayFormats: {
      'minute': 'HH:mm',
      'hour': 'HH:mm',
      min: '00:00',
      max: '23:59'
    },
}}],
    },
  }
};
var ctx = document.getElementById("myChart").getContext("2d");
new Chart(ctx, config);
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart"></canvas>  
   </body>
</html>

Related Tutorials