I am working in an angular project and designing d3 pie charts. Everything works fine. But my problem is that I am not able to access class private variable inside a function.
I am working in an angular project and designing d3 pie charts. Everything works fine. But my problem is that I am not able to access class private variable inside a function.
Scope issue. Change
.attr('y', function (d, i) { return (this.legendHeight * (i + 1))})
To
.attr('y', (d, i) => { return (this.legendHeight * (i + 1))})
The problem you are facing can be explaned:
within your function (d, i) { return (this.legendHeight * (i + 1))} it so happens to be that this referes to another context than you might expect.
try changing it to an Arrow notation, like (d,i) => this.legendHeight * (i + 1) to solve your issue.
If you cannot use this notation you will need to make a local reference to your value of legendHeight