开发者

How to know that this is the last iteration of a function

开发者 https://www.devze.com 2023-03-02 01:31 出处:网络
I am having the below function which represents X axis of a Chart. Currently, in this function, \'n\' has many iterations which pre开发者_运维知识库sent 0, 25, 50, depending upon the values selected

I am having the below function which represents X axis of a Chart.

Currently, in this function, 'n' has many iterations which pre开发者_运维知识库sent 0, 25, 50, depending upon the values selected dynamically.

Is there any possibility by which we can know if this is the last iteration of n?

xaxis: {showLabels: true, noTicks: 7,tickFormatter: function(n)
{
    var k = n;

    if(k==7) // This is not working
        return NewdateData[NewdateData.length-1]; 
    else  
        return NewdateData[k];      
}


Reducing your function to a minimum works well comparing n with this.noTicks:

var xaxis = {showLabels: true, noTicks: 7,tickFormatter: function(n){
    return n === this.noTicks;
}};
console.log(xaxis.tickFormatter(1)); //false
console.log(xaxis.tickFormatter(7)); //true

Are you calling it the same way, ... .xaxis.tickFormatter(...) ?

0

精彩评论

暂无评论...
验证码 换一张
取 消