Skipping Weekend data in Candlestick Chart - CanvasJS JavaScript Charts

Skipping Weekend data in Candlestick Chart - CanvasJS JavaScript Charts

by canvasjs

HTML

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>

JavaScript

var chart = new CanvasJS.Chart("chartContainer", {
  title:{
    text: "Skipping Weekend Data in Candlestick Chart"
  },  
  axisY: {
    includeZero:false,
    title: "Prices",
    prefix: "$ "
  },
  axisX: {    
    valueFormatString: "DDD"
  },
  data: [
    {
      type: "candlestick",
      dataPoints: [
        { x: new Date(2012, 01, 06) ,y:[5283, 5348, 5032, 5229]},
        { x: new Date(2012, 01, 07) ,y:[5220, 5448, 5164, 5258]},
        { x: new Date(2012, 01, 08) ,y:[5276, 5735, 5215, 5703]},
        { x: new Date(2012, 01, 09) ,y:[5704, 5815, 4888, 5619]},
        { x: new Date(2012, 01, 10) ,y:[5609, 5885, 5548, 5879]},
        { x: new Date(2012, 01, 11) ,y:[5296, 5378, 5154, 5248]},
        { x: new Date(2012, 01, 12) ,y:[5296, 5378, 5154, 5248]},
        { x: new Date(2012, 01, 13) ,y:[6040, 6052, 5671, 5693]},
        { x: new Date(2012, 01, 14) ,y:[5702, 5971, 5604, 5682]},
        { x: new Date(2012, 01, 15) ,y:[5697, 5962, 5477, 5930]}
      ]
    }
  ]
});

for(var i = 0; i< chart.options.data.length; i++)
  chart.options.data[i].dataPoints = chart.options.data[i].dataPoints.filter(skipWeekend);

chart.render();

function skipWeekend(dps) {
  return dps.x.getDay() !== 6 && dps.x.getDay() !== 0;
}