@arshad,
The code shared above seems to be working fine. Please take a look at this StackBlitz project for the same.
Can you kindly create a sample project reproducing the issue either in StackBlitz or locally & share it with us over Google-Drive or Onedrive. Also, kindly brief us more about the issue you are facing along with the version of CanvasJS StockChart that you are using so that we can understand the scenario better and help you out.
—-
Manoj Mohan
Team CanvasJS