我在使用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);
有人能提供一个例子吗?
答案 0 :(得分:69)
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);
那应该有用;)
答案 1 :(得分:55)
options: {
animation: {
duration: 0
}
}
答案 2 :(得分:8)
要防止阅读回答该特定示例的所有已接受答案,请在图表js中禁用动画:
在初始化特定图表类型时,在您的选项中传递一个对象,并使用以下键/值对:animation: false
。例如myChart.Bar(myCanvas, {animation:false});
答案 3 :(得分:4)
这应该可以解决问题:
chartOption = {
animation:{
duration: 0
}
}
答案 4 :(得分:4)
尝试一下:
options: {
animation: {
duration: 0, // general animation time
},
hover: {
animationDuration: 0, // duration of animations when hovering an item
},
responsiveAnimationDuration: 0, // animation duration after a resize
}
答案 5 :(得分:4)
这也可以在全球范围内完成:
Chart.defaults.global.animation.duration = 0
通过:https://www.chartjs.org/docs/latest/configuration/animations.html#animation-configuration
答案 6 :(得分:4)
根据文档(https://www.chartjs.org/docs/latest/general/performance.html#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
}
});
答案 7 :(得分:3)
options{
animation: false
}
答案 8 :(得分:3)
您好,以下3个选项可用于禁用动画
1)禁用动画:
var myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
animation: false,
}
});
2)减少动画持续时间为0
var myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
animation: {
duration: 0,
},
});
3)全局选项:
Chart.defaults.global.animation = false;
var myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
}
});