I am currently trying to add a counter animation to the values presented once you click on a specific slice of the donut chart I have created, the counter will count up to the data values attached to that specific slice, however the animation is awfully slow for larger numbers as seen with the middle data.
I want to know how I can speed up the animation, and additionally how I would be able to show the value as a double with decimals, right now when you hover the slices of the chart, the tooltip shows the correct value, e.g 1399,99, however the counter in the centre of the chart will count to 1400 instead.
$(function() {
// Create the chart
addLabel = function(point) {
$('.cLabel').remove();
var i = 0,
text = '<span style="color: #323232; font-size: 14px;">' + point.name + '</span><br/>' + '<span style="font-size: 16px; color: #323232;">kr ' + point.subtotal + ' / måned</span><br/>' + '<span style="font-size: 14px; color: #323232;">' + point.y + '</span><br/>',
chart = point.series.chart,
renderer = chart.renderer;
chart.renderer.label(text, chart.chartWidth / 2.02, chart.chartHeight / 2.14).attr({
'text-anchor': 'middle',
}).addClass('cLabel').add();
var intervalsubtotal = setInterval(function() {
if (i < point.subtotal) {
i++;
$('.cLabel')[0].lastChild.lastChild.previousSibling.innerHTML = 'kr ' + i + ' / måned';
} else {
clearInterval(interval);
}
}, 10 / point.subtotal)
var j = 0;
var intervalusers = setInterval(function() {
if (j < point.y) {
j++;
$('.cLabel')[0].lastChild.lastChild.innerHTML = 'Antal brugere: ' + j;
} else {
clearInterval(interval);
}
}, 500 / point.y
)};
- Animation is too slow
- Does not show values with decimals (double)
- Whenever you click another value the counter starts to glitch if its already counting (may be fixed with increased animation speed)