Home forums Using CanvasJS Incorrect label displayed for quarter of the year Reply To: Incorrect label displayed for quarter of the year

#19213

Ravneet03
Member

Given below is what my understanding is of the problem
1. stripLines is an array.
2. As per solution jsfiddle given by you guys. Everytime the addTO(“stripLines”,{}); method is called (using for loop) new values are added to the new index location. eg.
addTO("stripLines",{Q3 17}); //added to index 0
addTo("stripines", {value: Q4 17}); //added to index 1 .. and so on
3. Now I am using the older version of canvasJS and addTo method is not available and the way my code is written the value to stripLines is added as below.
chart.options.axisX.stripLines = [{..}]
Everytime the for loop is executed value at stripLines[0] i.e. index 0 is getting overwritten
e.g.
chart.options.axisX.stripLines = [{Q317}] //index 0
chart.options.axisX.stripLines = [{Q4 17}] //index 0
As a result I get only one stripLine in my chart at the end of for loop.

So Now I need a way that new values are written to new index everytime for loop is called.

so I tried this

var j= 0;
for( var i = minimum; i < maximum; i+= interval){
        value = new Date( i - (24 * 60 * 60 * 1000)).setHours(0, 0, 0, 0);
        interval = (getDaysInMonth(new Date(i).getMonth(), new Date(i).getFullYear())) * 24 * 60 * 60 * 1000;

        chart.options.axisX.stripLines[j]= [{
              value: value,
              label: value,
              labelPlacement: "outside",
              color: "#a3a3a3",              
              labelBackgroundColor: "transparent",
              labelFontColor: "#a3a3a3",
              labelFormatter: function (e) {
                var count = (new Date(e.stripLine.value).getMonth()/3 << 0) + 1;
                return "Q" + count + " " + CanvasJS.formatDate(e.stripLine.value, "YY");
              }
 }];
j++;
}

But this is not working and stripLines are not displayed. JSfiddle for the same