align zeros on chart with multi axes on line chart - Javascript Chart.js

Javascript examples for Chart.js:Line Chart

Description

align zeros on chart with multi axes on 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/jquery/2.1.3/jquery.min.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(){//from w  ww. ja va  2  s.  c  om
var canvas = document.getElementById('chart');
new Chart(canvas, {
  type: 'line',
  data: {
    labels: ['1', '2', '3', '4', '5'],
    datasets: [{
      label: 'A',
      yAxisID: 'A',
      data: [-10, 96, 84, 76, 69]
    }, {
      label: 'B',
      yAxisID: 'B',
      data: [-2, 3, 5, 2, 3]
    }]
  },
  options: {
    scales: {
      yAxes: [{
        id: 'A',
        type: 'linear',
        position: 'left',
        ticks : {
           max: 100,
          min: -50,
          stepSize: 50
        }
      }, {
        id: 'B',
        type: 'linear',
        position: 'right',
            ticks : {
           max: 6,
          min: -3,
          stepSize: 3
        }
      }]
    }
  }
});
    }

      </script> 
   </head> 
   <body> 
      <div style="width:75%;"> 
         <canvas id="chart"></canvas> 
      </div>  
   </body>
</html>

Related Tutorials