rendro / easy-pie-chart

easy pie chart is a lightweight plugin to draw simple, animated pie charts for single values
http://rendro.github.io/easy-pie-chart
MIT License
2.07k stars 501 forks source link

Unable to update pie chart #178

Open Zaid-Mirza opened 8 years ago

Zaid-Mirza commented 8 years ago

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);

ghost commented 7 years ago

Hi Zaid, did you found solution to this problem? I have the same problem here! Thanks

BBoyBreaker commented 7 years ago

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; } });`