First of all, I would like to thank you for the amazing work you're doing with GSAP... it really is an awesome tool and and I really love to work with it Well, I'm combining GSAP and chart.js library to do some animated charts for an online CV and yesterday I ran into a strange issue. I'm usually bringing empty charts (with values of 0) in the screen using timelinemax and then updating the charts value with a callback function (in this case the function updatedoughnuts()) to have a nice animation effect on my charts.
var tween6 = new TimelineMax();
tween6.staggerTo(".doughnut", 2, {marginLeft:"0px", ease:Power4.easeOut});
tween6.call(updatedoughnuts);
tween6.to(legend, 1, {opacity:1, alpha:1, ease:Quart.easeOut}, 2);
function updatedoughnuts() {
mydoughnutgraph1.segments[0].value = 120;
mydoughnutgraph1.segments[1].value = 30;
mydoughnutgraph1.update();
mydoughnutgraph2.segments[0].value = 80;
mydoughnutgraph2.segments[1].value = 70;
mydoughnutgraph2.update();
alert("the function has been called");
};
The weird thing is that the function is called (I have the alert box) but my doughnut graphs are not updated. But even stranger is that if I remove the callback inside the timeline and call the function outside of it, then it works like a charm (see the codepen that reproduce the error):
var tween6 = new TimelineMax();
tween6.staggerTo(".doughnut", 2, {marginLeft:"0px", ease:Power4.easeOut});
tween6.to(legend, 1, {opacity:1, alpha:1, ease:Quart.easeOut}, 2);
updatedoughnuts();
I really don't understand this behaviour... I tried different callback with onComplete in the staggerTo or using a delayedCall but I always get the same behaviour. I also used the same method with other types of chart and I had no problem to update the charts values with a callback... Or maybe I just miss somth completly obvious
I really hope you guys can help me on this one.
Thanks in advance