Chartjs-Set animation dynamically in Chart.JS

1👍

You are trying to set the options wrong. Both versions work. If you want to set it as default you will have to put it like this: Chart.defaults.global.animation.duration = animation ? 1000 : 0. You can also put it in your options object like this:

const anim_duration = { duration : animation ? 1000 : 0 }

options: {
  animation: anim_duration
}

Fiddle: https://jsfiddle.net/Leelenaleee/58pxb1j2/9/

EDIT after comment clarification:
Set the animation in your update method CHART.options.animation.duration = animation ? 1000 : 0; then call the update.

Leave a comment