Format Bar Chart's yAxis labels in Chart.js - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Format Bar Chart's yAxis labels in Chart.js

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/Chart.js/2.1.6/Chart.bundle.min.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from ww  w  . jav  a2s.c  o  m*/
var data = {
  "labels": ["Label1", "Label2", "Label3", "Label4", "Label5"],
  "datasets": [{
    "label": "Variation",
    "data": ["56", "-82.3", "25.7", "32.2", "49.99"],
    "borderWidth": 1,
    "backgroundColor": "rgba(231, 76, 60, 0.2)",
    "borderColor": "rgba(231, 76, 60, 1)"
  }]
};
var myBarChart = new Chart($("#myCanvas"), {
  type: 'bar',
  data: data,
  maintainAspectRatio: false,
  options: {
        scales: {
            yAxes: [{
                ticks: {
                    callback: function(value, index, values) {
                        return value + ' %';
                    }
                }
            }]
        }
    }
});
    }

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

Related Tutorials