用 Charts.js 禁用动画

我无法用 charts.js 关闭动画。

这是我的暗号:

var pieData = [
{
value: 30,
color:"#F38630"
},
{
value : 50,
color : "#E0E4CC"
},
{
value : 100,
color : "#69D2E7"
}
];


var myPie = new Chart(document.getElementById("canvas").getContext("2d")).Pie(pieData);

有人能举个例子吗?

118881 次浏览
var pieData = [{
value: 30,
color: "#F38630"
},
{
value: 50,
color: "#E0E4CC"
},
{
value: 100,
color: "#69D2E7"
}];


var pieOptions = {
animation: false
};


var ctx = document.getElementById("canvas").getContext("2d");
var myPie = new Chart(ctx).Pie(pieData, pieOptions);

That should work ;)

To prevent reading all of the accepted answer that answers that particular example, to disable animation in chart js:

Pass an object in your options when initialising the particular chart type and use the following key/value pair: animation: false. e.g. myChart.Bar(myCanvas, {animation:false});

options: {
animation: {
duration: 0
}
}

This should do the trick:

    chartOption = {
animation:{
duration: 0
}
}
options{
animation: false
}

Hi following 3 options works for the disabling the animation

1)Disable animation:

var myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
animation: false,
}
});

2)Reduce animation duration for 0

var myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
animation: {
duration: 0,
},
});

3)Global Option:

 Chart.defaults.global.animation = false;
var myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
}
});

Try this:

options: {
animation: {
duration: 0, // general animation time
},
hover: {
animationDuration: 0, // duration of animations when hovering an item
},
responsiveAnimationDuration: 0, // animation duration after a resize
}

This can also be done globally:

Chart.defaults.global.animation.duration = 0

Via: https://www.chartjs.org/docs/latest/configuration/animations.html#animation-configuration

According to the docs (https://www.chartjs.org/docs/latest/general/performance.html#disable-animations) here is the way to completely disable animations:

new Chart(ctx, {
type: 'line',
data: data,
options: {
animation: {
duration: 0 // general animation time
},
hover: {
animationDuration: 0 // duration of animations when hovering an item
},
responsiveAnimationDuration: 0 // animation duration after a resize
}
});

For those who can't disable animations when they use:

const chartOptions = {
animation: {
duration: 0,
},
};

Give the Chart a fixed height. If the parent element is responsive it may cause the chart to re-render and make it seem as if animations are not disabled.