Last active
May 28, 2017 21:48
-
-
Save ricardocosta/f4751f9a73113df32c9be5cda10ddecf to your computer and use it in GitHub Desktop.
animationDuration not respected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div class="myChartDiv"> | |
<canvas id="myChart" width="600" height="400"></canvas> | |
</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js"> </script> | |
<script> | |
var ctx = document.getElementById("myChart"); | |
var lastactive = []; | |
var myChart = new Chart(ctx, { | |
type: 'doughnut', | |
data: { | |
datasets: [{ | |
data: [ | |
Math.round(1 * 100), | |
Math.round(2 * 100), | |
Math.round(3 * 100), | |
Math.round(5 * 100), | |
Math.round(8 * 100) | |
], | |
borderWidth: 0, | |
backgroundColor: [ | |
'#C8102E', | |
'#F6D155', | |
'#F2552C', | |
'#88B04B', | |
'#5487A4' | |
], | |
hoverBorderWidth: 0, | |
label: 'Dataset 1' | |
}], | |
labels: [ | |
'Red', | |
'Yellow', | |
'Orange', | |
'Green', | |
'Blue' | |
] | |
}, | |
options: { | |
animationDuration: 100, | |
hover: { | |
onHover: function(e, el) { | |
var currentIndex = el[0] && el[0]._index | |
var lastIndex = lastactive[0] && lastactive[0]._index | |
if (currentIndex == lastIndex) { | |
return; | |
} else if (el[0]) { | |
el[0]._chart.update() | |
el[0]._model.outerRadius += 10 | |
lastactive = el | |
} else { | |
lastactive[0]._chart.update() | |
lastactive = [] | |
} | |
} | |
}, | |
onClick: function() {console.log('clicked')}, | |
cutoutPercentage: 80, | |
maintainAspectRatio: false, | |
animation: { | |
easing: 'linear', | |
duration: 5000 | |
}, | |
legend: { | |
display: false | |
}, | |
layout: { | |
padding: 30 | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment