Single bar with background using Chart.js - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Single bar with background using Chart.js

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Chart.js v2 stacked bar chart</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.3/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from  w ww  .  ja v a 2  s .  c  om*/
var value = 57866;
var max = 80000;
var bar_ctx = document.getElementById('bar-chart');
var bar_chart = new Chart(bar_ctx, {
  type: 'horizontalBar',
  data: {
    labels: [],
    datasets: [{
      data: [value],
      backgroundColor: "rgba(51,230,125,1)"
    }, {
      data: [max - value],
      backgroundColor: "lightgrey",
    }, ]
  },
  options: {
    legend: {
      display: false
    },
    tooltips: {
      enabled: false
    },
    scales: {
      xAxes: [{
        display: false,
        stacked: true
      }],
      yAxes: [{
        display: false,
        stacked: true
      }],
    } // scales
  } // options
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="bar-chart" height="20"></canvas>  
   </body>
</html>

Related Tutorials