Reputation: 3941
I am using a plugin that creates donut charts called easyPieChart. I need to update the data that is passed to the plugin. This is done by the following:
$(this).data('easyPieChart').update(40);
This basically sets the value of the donut to 40%. I need to loop through a series of divs and update the donut charts in each one. If I was to do the following, all donuts would be updated to 40%:
$('.percentage').each(function() {
$(this).data('easyPieChart').update(40);
});
I need to create an array of integers to pass, so as we are iterating on .percentage
a different value is passed to each. So for instance, the first .percentage
receives a value of 40, the second 60, etc.
if I had an array with all of the numbers, how would I use it with the each loop:
var numbToUse = [40,30,60];
Upvotes: 0
Views: 364
Reputation: 26320
The first argument of each
is the index, so you can use it to get it's value, like the following:
var numbToUse = [40,30,60];
$('.percentage').each(function(i) {
$(this).data('easyPieChart').update(numToUse[i]);
});
Upvotes: 2