Chart.js to color individual bars differently - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Chart.js to color individual bars differently

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-beta/Chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){//  w  w  w  .j  a  va  2s  . co m
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: ["R", "B", "G", "Y"],
            datasets: [{
                    label: 'value',
                    data: [12, 19, 1, 14],
                    backgroundColor: ["red", "blue", "green", "yellow"],
            }]
        }
});
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart" width="600" height="300"></canvas>  
   </body>
</html>

Related Tutorials