Make rectangle in bar chart chart.js - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Make rectangle in bar chart 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.2.1/Chart.min.js"></script> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/0.5.5/chartjs-plugin-annotation.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//from   w  w w .j a  va  2s  .c o m
var ctx = document.querySelector(".myChart").getContext('2d');
var myChart = new Chart(ctx, {
   type: 'bar',
   data: {
      labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Nov", "Dec"],
      datasets: [{
         label: 'Findings',
         data: [0, 45],
         backgroundColor: 'rgba(54, 162, 235, 0.2)',
         borderColor: 'rgba(54, 162, 235, 1)',
         borderWidth: 1
      }]
   },
   options: {
      scales: {
         yAxes: [{
            display: true,
            ticks: {
               beginAtZero: true,
               steps: 20,
               stepValue: 20,
               max: 60,
               min: 0
            }
         }]
      },
      annotation: {
         annotations: [{
            type: 'box',
            drawTime: 'beforeDatasetsDraw',
            yScaleID: 'y-axis-0',
            yMin: 40,
            yMax: 50,
            backgroundColor: 'rgba(0, 255, 0, 0.1)'
         }]
      }
   }
});
    }

      </script> 
   </head> 
   <body> 
      <canvas class="myChart" height="150"></canvas>  
   </body>
</html>

Related Tutorials