Chartjs custom y axis values - Javascript Chart.js

Javascript examples for Chart.js:Axis

Description

Chartjs custom y axis values

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.0.0/Chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){// w w w .  j  a  v  a2  s .c  om
var ctx = document.getElementById("myGraph1").getContext("2d");
var data = {
    labels: ["January", "February", "March", "April", "May"],
    datasets: [
        {
            label: "You",
            backgroundColor: "#3a3b74",
            borderWidth: 0,
            hoverBackgroundColor: "#3a3b74",
            data: [5,6,2,4,1.5],
        },
    ]
};
var myBarChart = new Chart(ctx, {
    type: 'bar',
    data: data,
   options: {
        scales: {
         xAxes: [{
            barPercentage:1,
            categoryPercentage:0.5,
            gridLines:{
               display:false
            },
            ticks: {
               fontColor:"#8f9092"
            }
         }],
         yAxes: [{
            display: true,
            scaleLabel: {
               show: true
            },
            gridLines:{
               color:"#ecedef"
            },
            ticks: {
               beginAtZero:true,
               stepSize: 1.3,
               fontColor:"#8f9092",
               callback:function(value) {
                   var x = ["January", "February", "March", "April", "May", "June", "July"];
                     return x[value | 0];
               }
            }
         }]
        },
      legend: {
         position:'bottom'
       }
    }
});
    }

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

Related Tutorials