Show all values in Chart js y axis - Javascript Chart.js

Javascript examples for Chart.js:Axis

Description

Show all values in Chart js y axis

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://code.jquery.com/jquery-1.12.2.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.4/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//  w  w  w  . j  a  va2 s  .  com
var data = {
  labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  datasets: [{
    label: "My First dataset",
    fill: false,
    lineTension: 0,
    backgroundColor: "rgba(75,192,192,0.4)",
    borderColor: "rgba(75,192,192,1)",
    borderCapStyle: 'butt',
    borderDash: [],
    borderDashOffset: 0.0,
    borderJoinStyle: 'miter',
    pointBorderColor: "rgba(75,192,192,1)",
    pointBackgroundColor: "#fff",
    pointBorderWidth: 2,
    pointHoverRadius: 5,
    pointHoverBackgroundColor: "rgba(75,192,192,1)",
    pointHoverBorderColor: "rgba(220,220,220,1)",
    pointHoverBorderWidth: 2,
    pointRadius: 1,
    pointHitRadius: 10,
    data: [0, 1, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13],
  }]
};
var options = {
  scales: {
    yAxes: [{
      ticks: {
        min: 0,
        max: 13,
        stepSize: 1,
        callback: function(value, index, values) {
          switch (value) {
            case 0:
              return 'XC';
            case 1:
              return 'C';
            case 2:
              return 'B';
            case 3:
              return 'A';
            case 4:
              return 'A+';
            case 5:
              return 'BA';
            case 6:
              return 'N+';
            case 7:
              return 'C-';
            case 8:
              return 'D+';
            case 9:
              return 'D';
            case 10:
              return 'D-';
            case 11:
              return 'N';
            case 12:
              return 'N-';
            case 13:
              return 'NR';
            default:
              return '';
              break;
          }
        }
      }
    }]
  }
};
var ctx = $('#chart');
var chart = new Chart(ctx, {
  type: 'line',
  data: data,
  options: options
});
    }

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

Related Tutorials