Set minimum step size in column chart - Javascript Chart.js

Javascript examples for Chart.js:Column Chart

Description

Set minimum step size in column chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>chart.js 2.0 bar</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){// w ww .  java 2s.  c  o m
var canvas = document.getElementById('myChart');
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: 2,
            hoverBackgroundColor: "rgba(255,99,132,0.4)",
            hoverBorderColor: "rgba(255,99,132,1)",
            data: [1, 0, 0, 0, 1, 0, 0],
        }
    ]
};
var option = {
   scales: {
     yAxes:[{
          stacked:true,
        gridLines: {
           display:true,
          color:"rgba(255,99,132,0.2)"
        },
        ticks: {
                min: 0,
                callback: function(value, index, values) {
                    if (Math.floor(value) === value) {
                        return value;
                    }
                }
            }
    }],
    xAxes:[{
          gridLines: {
           display:false
        }
    }]
  }
};
var myBarChart = Chart.Bar(canvas,{
   data:data,
  options:option
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart" width="400" height="200"></canvas>  
   </body>
</html>

Related Tutorials