Unable to update pie chart
Zaid-Mirza opened this issue · comments
Scenaria is,
I m updating data-percent value dynamically of pie chart using Jquery. Value updated sucessfully but animation does not happen again. I tried below code but it gives error update is not defined
$('.chart-circle').data('easyPieChart').update(40);
Hi Zaid, did you found solution to this problem?
I have the same problem here! Thanks
i got it working after doing the following :
`var active = false;
var element = document.querySelector('.chart');
var chart = new EasyPieChart(element, {
// your options goes here
});
chart.update(0);
function isScrolledIntoView(elem)
{
var docViewTop = jQuery(window).scrollTop();
var docViewBottom = docViewTop + jQuery(window).height();
var elemTop = jQuery(elem).offset().top;
var elemBottom = elemTop + jQuery(elem).height();
return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
jQuery( document ).ready(function() {
// in my case i only update it when the user is scrolled to it
if(isScrolledIntoView(jQuery('.chart')) && !active) {
charts.forEach(function(chart) {
chart.update(chart.el.dataset.percent);
});
active = true;
}
});`