Show text in both y axis in dual axis chart js - Javascript Chart.js

Javascript examples for Chart.js:Axis

Description

Show text in both y axis in dual axis chart js

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>chart.js 2.1</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.0/Chart.bundle.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//w w w.  jav  a 2 s.  co  m
      var lineChartData = {
         labels: ["January", "February", "March", "April", "May", "June", "July"],
         datasets: [{
            label: "My First dataset",
            data: [50, 85, 56, 50, 60, 70, 80],
            yAxisID: "y-axis-1",
            borderColor: "#0ad4e6"
         }, {
            label: "My Second dataset",
            data: [35, 45, 75, 40, 55, 73, 82],
            yAxisID: "y-axis-2",
            borderColor: "#f6c63e"
         }]
      };
         var ctx = document.getElementById("canvas").getContext("2d");
         window.myLine = Chart.Line(ctx, {
            data: lineChartData,
            options: {
               responsive: true,
               hoverMode: 'label',
               stacked: false,
               title: {
                  display: false,
                  text: 'Chart.js Line Chart - Multi Axis'
               },
               animation: {
                  duration: 0
               },
               legend: {
                  display: false,
                  position: 'top',
               },
               scales: {
                  xAxes: [{
                     display: true,
                     gridLines: {
                        offsetGridLines: false
                     }
                  }],
                  yAxes: [{
                     type: "linear", 
                     display: true,
                     position: "left",
                     id: "y-axis-1",
                     scaleLabel: {
                        display: true,
                        labelString: "Cost"
                     }
                  }, {
                     type: "linear", 
                     display: true,
                     position: "right",
                     id: "y-axis-2",
                     scaleLabel: {
                        display: true,
                        labelString: "Students",
                     },
                     gridLines: {
                        drawOnChartArea: false,
                     },
                  }],
               }
            }
         });
    }

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

Related Tutorials