Add panning to chart in chartjs - Javascript Chart.js

Javascript examples for Chart.js:Chart Configuration

Description

Add panning to chart 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://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script> 
      <script type="text/javascript" src="https://npmcdn.com/Chart.Zoom.js@0.3.0/Chart.Zoom.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//  www  .ja v  a2s  .  c  om
var ctx = document.getElementById("canvas").getContext('2d');
var myChart = new Chart(ctx, {
   type: 'bar',
   data: {
      labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept'],
      datasets: [{
         label: '# of Votes',
         data: [12, 19, 3, 5, 2, 5, 9, 4, 11]
      }]
   },
   options: {
      pan: {
         enabled: true,
         mode: 'x',
      },
      zoom: {
         enabled: true,
         mode: 'x',
      }
   }
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="canvas" height="180"></canvas>  
   </body>
</html>

Related Tutorials