'CanvasJS stock chart axisY doesn't update automatically with my data

I have tried the stock chart with sample data present on the CanvasJS site and it updates the Y axis everytime I scroll through it, but when I pass my data to that function it scrolls but without updating the Y-axis.

First I was trying to fetch data from array of arrays but the sample chart was using array of JSON so I converted my data to be of the exact similar manner but to no avail. I would be very thankful if you can help me on this.

My data

window.onload = function () {
     CanvasJS.addColorSet("greenShades",
                   [//colorSet Array

                   "red",
                   "#008080",
                   "#2E8B57",
                   "#3CB371",
                   "#90EE90"                
                   ]);
     var dataPoints = [];
     var stockChart = new CanvasJS.StockChart("stockChartContainer",{
       zoomEnabled: true,
       theme: "light2",
       colorSet: "greenShades",
       exportEnabled: true, //false
       title:{
         text:""
       },
       subtitles: [{
         text: ""
       }],
       rangeSelector: {        
         buttons: [
           {
             range: 10, //Change it to 6
             rangeType: "day",
             label: "10D"
           },
           {
             range: 1, //Change it to 6
             rangeType: "month",
             label: "1M"
           },
           {
             range: 6, //Change it to 6
             rangeType: "month",
             label: "6M"
           },
           {
             range: 1, //Change it to 6
             rangeType: "year",
             label: "1Y"
           },
           {            
             rangeType: "all",
             label: "All" //Change it to "All"
           }
         ]
       },
       charts: [{
         axisX: {
           
         },
         axisY: {
           prefix: "",
           suffix: "",
           title: "",
           viewportMinimum: 20,
           viewportMaximum: 200,
           titleFontSize: 14
         },
         data: [{
           type: "area",
           xValueFormatString: "MMM YYYY",
           yValueFormatString: "#,###.##M",
           dataPoints : dataPoints
         }]
       }],
       navigator: {
         // slider: {
         //   minimum: new Date(2010, 00, 01),
         //   maximum: new Date(2014, 00, 01)
         // }
       }
     });
     $.getJSON("https://financialmodelingprep.com/api/v3/historical-price-full/AAPL?apikey=API_KEY", function(data) {
      
       for(var i = 0; i < data.historical.length; i++){
         dataPoints.push({x: new Date(data.historical[i].date), y: Number(data.historical[i].close)});
       }
       console.log(dataPoints)
       stockChart.render();
     });
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source