Chart.js: How to stop animation of bar chart

Created on 26 May 2014  路  6Comments  路  Source: chartjs/Chart.js

can i stop animation of graph ?

All 6 comments

option "animation:false" -> No animation at all;

There is no possibility to suspend the animation.

@FVANCOP This should be a feature request. There should really be a hook for this kind of thing.

Suggested approaches: (based on pre existing knowledge not actual code)

  • wrap window.requestAnimationFrame in an if statement to check that has a callback. You can toggle the truthiness on a per chart basis.
  • provide a callback where window.requestAnimationFrame(). can be called. I will see if the onProgress hook can be used.

If I look at the code and see where I can introduce it will you give me a try?

@dewwwald pretty old ticket and I'm not sure to understand what you are suggesting?

I don't think it's about cancelling the requested animation frame, but instead to cancel the whole animation, which (as 2017) can be achieved using chart.stop().

Oh really? So you can stop an animation until a more desired event occurs for the animation to execute?

3 use cases (since the initial question is quite ambiguous):

  • disable animations (@FVANCOP answer)
  • cancelling in progress animations (that's the point of my previous comment)
  • deferring the whole chart animations. Can be achieved in 2.5 by writing a simple plugin: the beforeRender hook allows to cancel rendering the chart (and thus animations) if a plugin returns false and trigger a new render() at a more appropriated moment.

I wrote the deferred plugin to delayed the initial data animation (not the chart drawing) until the user scrolls to the chart. I hooked the beforeDatasetsUpdate since it was the only cancellable hook at the time of 2.1.5. When 2.5 will be released, I should extend my plugin to beforeRender or even beforeUpdate.

@simonbrunel Cool, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frlinw picture frlinw  路  3Comments

JAIOMP picture JAIOMP  路  3Comments

akashrajkn picture akashrajkn  路  3Comments

bytesnz picture bytesnz  路  3Comments

JewelsJLF picture JewelsJLF  路  3Comments