Chart.js labels displaying - Javascript Chart.js

Javascript examples for Chart.js:Chart Label

Description

Chart.js labels displaying

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Chart.js Configuring Time Scale</title> 
   </head> 
   <body translate="no"> 
      <div id="canvas-holder" style="width: 50%;"> 
         <canvas id="canvas"></canvas> 
      </div> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script> 
      <script>
      // define some colors to use in our chart
var chartColors = {//w  ww .jav a 2  s .  c o m
   red: 'rgb(255, 99, 132)',
   orange: 'rgb(255, 159, 64)',
   yellow: 'rgb(255, 205, 86)',
   green: 'rgb(75, 192, 192)',
   blue: 'rgb(54, 162, 235)',
   purple: 'rgb(153, 102, 255)',
   grey: 'rgb(231,233,237)'
};
// build the chart dataset and options config
var config = {
  type: 'line',
  data: {
    datasets: [{
      label: "My Dataset",
      fill: false,
      lineTension: 0.1,
      borderColor: "#8CCEC2",
      backgroundColor: "#8CCEC2",
      borderCapStyle: 'butt',
      borderJoinStyle: 'miter',
      pointRadius:0,
      data: [
        {
          x:moment((new Date()).toISOString()).subtract(1,"days")
          ,y:9000
        },
        {
          x:moment((new Date()).toISOString()).subtract(2,"days")
          ,y:11000
        },
        {
          x:moment((new Date()).toISOString()).subtract(3,"days")
          ,y:8000
        },
        {
          x:moment((new Date()).toISOString()).subtract(4, "days")
          ,y:10000
        },
        {
          x:moment((new Date()).toISOString()).subtract(5, "days")
          ,y:9000
        }
      ],
      spanGaps: false
    }]
  },
  options: {
    responsive: true,
    title: {
      display: true,
      text: 'Chart.js Configuring Time Scale'
    },
    tooltips: {
      mode: 'index',
      intersect: false,
    },
    hover: {
      mode: 'nearest',
      intersect: true
    },
    scales: {
      xAxes: [{
        gridLines: {
          display: false,
        },
        type: "time",
        time: {
          unit: 'day',
        }
      }],
      yAxes: [{
        ticks:{
          stepSize: 10000
        }
      }]
    }
  }
};
// create our chart
var myLine = new Chart($('#canvas'), config);
      //# sourceURL=pen.js
    
      </script>  
   </body>
</html>

Related Tutorials