0

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

1 Answer 1

2

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]);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.