Animations

    config setup

    1. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
    2. datasets: [{
    3. label: 'Looping tension',
    4. data: [65, 59, 80, 81, 26, 55, 40],
    5. fill: false,
    6. borderColor: 'rgb(75, 192, 192)',
    7. }]
    8. };

    Animations - 图2

    config setup

    1. const data = {
    2. labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
    3. datasets: [{
    4. label: 'Try hiding me',
    5. fill: false,
    6. borderColor: 'rgb(75, 192, 192)',
    7. }]
    8. };

    Animation configuration consists of 3 keys.

    These keys can be configured in following paths:

    • `` - chart options
    • datasets[type] - dataset type options
    • overrides[type] - chart type options

    These paths are valid under defaults for global confuguration and options for instance configuration.

    animation

    Namespace: options.animation

    NameTypeDefaultDescription
    durationnumber1000The number of milliseconds an animation takes.
    easingstring‘easeOutQuart’Easing function to use.
    delaynumberundefinedDelay before starting the animations.
    loopbooleanundefinedIf set to true, the animations loop endlessly.

    These defaults can be overridden in options.animation or dataset.animation and tooltip.animation. These keys are also Scriptable.

    Animations options configures which element properties are animated and how. In addition to the main , the following options are available:

    Namespace: options.animations[animation]

    NameOptionValue
    numbersproperties[‘x’, ‘y’, ‘borderWidth’, ‘radius’, ‘tension’]
    numberstype‘number’
    colorsproperties[‘color’, ‘borderColor’, ‘backgroundColor’]
    colorstype‘color’

    Note

    These default animations are overridden by most of the dataset controllers.

    transitions

    The core transitions are 'active', 'hide', 'reset', 'resize', 'show'. A custom transition can be used by passing a custom mode to . Transition extends the main animation configuration and .

    Default transitions

    To disable an animation configuration, the animation node must be set to false, with the exception for animation modes which can be disabled by setting the duration to 0.

    Easing

    Available options are:

    • 'easeInQuad'
    • 'easeOutQuad'
    • 'easeInOutQuad'
    • 'easeInCubic'
    • 'easeOutCubic'
    • 'easeInOutCubic'
    • 'easeInQuart'
    • 'easeOutQuart'
    • 'easeInOutQuart'
    • 'easeInQuint'
    • 'easeOutQuint'
    • 'easeInOutQuint'
    • 'easeInSine'
    • 'easeOutSine'
    • 'easeInOutSine'
    • 'easeInExpo'
    • 'easeInOutExpo'
    • 'easeInCirc'
    • 'easeOutCirc'
    • 'easeInOutCirc'
    • 'easeInElastic'
    • 'easeOutElastic'
    • 'easeInOutElastic'
    • 'easeInBack'
    • 'easeOutBack'
    • 'easeInOutBack'
    • 'easeInBounce'
    • 'easeOutBounce'
    • 'easeInOutBounce'

    See Robert Penner’s easing equations (opens new window).

    The animation configuration provides callbacks which are useful for synchronizing an external draw to the chart animation. The callbacks can be set only at main .

    Namespace: options.animation

    NameTypeDefaultDescription
    onProgressfunctionnullCallback called on each step of an animation.
    onCompletefunctionnullCallback called when all animations are completed.

    The callback is passed the following object:

    1. {
    2. // Chart object
    3. chart: Chart,
    4. // Number of animations still in progress
    5. currentStep: number,
    6. // `true` for the initial animation of the chart
    7. initial: boolean,
    8. // Total number of animations at the start of current animation
    9. }

    The following example fills a progress bar during the chart animation.