Change Chart JS Bar Chart Border to Dotted Line - Javascript Chart.js

Javascript examples for Chart.js:Bar Chart

Description

Change Chart JS Bar Chart Border to Dotted Line

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>chart.js 2.1</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.0/Chart.bundle.min.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/* w ww. j  a va 2  s .co m*/
var config = {
  type: 'bar',
  data: {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [{
      label: "My First dataset",
      backgroundColor: "rgba(255,99,132,0.2)",
      data: [65, 59, 80, 81, 56, 45, 40],
      borderColor: 'blue',
      borderWidth: 3,
    }]
  }
};
var ctx = document.getElementById("myChart").getContext("2d");
myChart = new Chart(ctx, config);
Chart.helpers.each(myChart.getDatasetMeta(0).data, function(rectangle, index) {
  rectangle.draw = function() {
    myChart.chart.ctx.setLineDash([10, 10]);
    Chart.elements.Rectangle.prototype.draw.apply(this, arguments);
  }
}, null);
    }

      </script> 
   </head> 
   <body> 
      <canvas id="myChart"></canvas>  
   </body>
</html>

Related Tutorials