Gradient colour in background Color in bar chart - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Gradient colour in background Color in bar chart

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head> 
      <title>Chart.js Gradients</title> 
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> 
      <style>

canvas {/*from ww w . ja v a 2 s  .  c o m*/
   display: block;
   max-width: 800px;
   margin: 60px auto;
}


      </style> 
   </head> 
   <body translate="no"> 
      <canvas id="bar-chart" width="400" height="300"></canvas> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script> 
      <script>
      var bar_ctx = document.getElementById('bar-chart').getContext('2d');
var purple_orange_gradient = bar_ctx.createLinearGradient(0, 0, 0, 600);
purple_orange_gradient.addColorStop(0, 'orange');
purple_orange_gradient.addColorStop(1, 'purple');
var bar_chart = new Chart(bar_ctx, {
    type: 'bar',
    data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 8, 14, 5],
                  backgroundColor: purple_orange_gradient,
        }]
    },
});
      //# sourceURL=pen.js
    
      </script>  
   </body>
</html>

Related Tutorials