add shadow for line chart - Javascript Chart.js

Javascript examples for Chart.js:Line Chart

Description

add shadow for line chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>chart.js shadow</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.7.2/Chart.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from  w  w  w .  ja va 2s  .c  o  m*/
let draw = Chart.controllers.line.prototype.draw;
Chart.controllers.line = Chart.controllers.line.extend({
    draw: function() {
           let ctx = this.chart.chart.ctx;
        ctx.save();
        ctx.shadowColor = 'red';
        ctx.shadowBlur = 12;
        ctx.shadowOffsetX = 0;
        ctx.shadowOffsetY = 5;
        ctx.stroke();
        draw.apply(this, arguments);
        ctx.restore();
    }
});
let ctx = document.getElementById("canvas").getContext('2d');
let myChart = new Chart(ctx, {
    type: 'line',
    options: {
       scales: {
          yAxes: [{
            gridLines: {
               display: true,
               lineWidth: 2,
              color: 'blue'
            }
          }],
               xAxes: [{
            gridLines: {
               display: true,
               lineWidth: 2,
              color: 'blue'
            }
          }],
        }
    },
    data: {
        labels: ["January", "February", "March", "April", "May", "June", "July"],
        datasets: [{
            label: "My First dataset",
            data: [65, 59, 80, 81, 56, 55, 40],
            borderColor: 'red',
            pointBackgroundColor: "#fff",
            pointBorderColor: "#ffb88c",
            pointHoverBackgroundColor: "#ffb88c",
            pointHoverBorderColor: "#fff",
            pointRadius: 4,
            pointHoverRadius: 4,
            fill: true
        }]
    }
});
    }

      </script> 
   </head> 
   <body> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script> 
      <canvas id="canvas" width="600" height="300" style="background-color:#fff"></canvas>  
   </body>
</html>

Related Tutorials