Search code examples
javascriptcanvasjs

CanvasJS - Removed empty holes / weekends etc from candlesticks graph


How do you remove the empty holes (like weekends etc) from a CanvasJS candlestick graph?

The graph leaves a big empty hole in the weekends etc, cause stock markets are closed.

I checked out documentation and google, but only thing I found was this post from 2015 kind of saying its not possible. https://canvasjs.com/forums/topic/hiding-nullempty-y-columns/ '

But CanvasJS has a build in option to show candlesticks.

Am I missing something?


Solution

  • It is not possible to skip weekends and holidays as the axis behaves linearly across the date range.

    In cases where you want to show only working days, then its better to use "label" instead of "x". But it requires you to format the date/time into required string format before assigning. You can use the formatDate() to do the same. Here is a page on label.

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

    Also please have a look at this jsFiddle.