Set Animation speed - ChartJS?

断了今生、忘了曾经 提交于 2020-08-06 14:24:20

问题


I am trying to set the animation speed of a pie chart in chartJS.

I've tried the following:

  1. numSteps: Number,

  2. animationSteps: Number

    3.Chart.defaults.global.animationSteps = Number;

None of these have changed the speed. Any advice?

 var myNewChart;
    var data = [
        {
        value: 30,
        label: "hello",
        color: "#F7464A"
      }, {
        value: 50,
        color: "#E2EAE9"
      }, {
        value: 100,
        color: "#D4CCC5"
      }, {
        value: 40,
        color: "#949FB1"
      }, {
        value: 100,
        color: "#4D5360"
      },

    ];


    var options = {
      animation: true,
      animationEasing: 'easeInOutQuart',
      animationSteps: 80,
      multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>"

    };


    var ctx = document.getElementById("myChart")
                                        .getContext("2d");

    myNewChart = new Chart(ctx).Doughnut(data, options);

回答1:


Use Chart.defaults.global.animation.duration = 3000;




回答2:


Use the animation object

options: {
        animation: {
            duration: 2000,
        },

I haven't see this documented anywhere, but it's incredibly helpful to not have to set the speed globally for every chart.



来源:https://stackoverflow.com/questions/42567002/set-animation-speed-chartjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!