Make integer scale in Chartjs - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

Make integer scale in Chartjs

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-2.2.3.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.bundle.js"></script> 
      <script type="text/javascript">
    window.onload=function(){// w w  w . ja  v a 2s.co m
var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [
        {
            label: "My First dataset",
            backgroundColor: "rgba(255,99,132,0.2)",
            borderColor: "rgba(255,99,132,1)",
            borderWidth: 1,
            hoverBackgroundColor: "rgba(255,99,132,0.4)",
            hoverBorderColor: "rgba(255,99,132,1)",
            data: [0, 1, 3, 0, 3, 1, 1],
            scaleOverride:true,
                 scaleSteps:4,
                 scaleStartValue:0,
                 scaleStepWidth:1
        }
    ]
};
var myBarChart = new Chart($("#a"), {
    type: 'horizontalBar',
    data: data,
    options: {
       scales: {
       yAxes: [{
           scaleLabel: {
           display: true
           }
       }],
       xAxes: [{
          ticks: {
                    min: 0,
                    stepSize: 1,
                    max: 4
                  },
                           scaleLabel: {
                              display: true
                           },
                        }]
      }
    }
});
    }

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

Related Tutorials