gpt4 book ai didi

javascript - Chart.js 在第一次加载时没有动画

转载 作者:行者123 更新时间:2023-12-05 07:49:13 25 4
gpt4 key购买 nike

我正在使用 Chart.js 绘制饼图,但它不会在第一次加载时播放动画 - 但如果我重新加载它就会播放。我做错了什么?

代码:

function make_chart(ctx, data, type="pie"){
var theChart = new Chart(ctx, {
type: type,
data: data,
animate:{
animateRotate: true,
duration: 1000,
animateScale: true,
animationSteps: 15
}

})
return theChart;
}

function example(ctx) {
var data = {
labels: [
"Red",
"Blue",
"Yellow"
],
datasets: [
{
data: [300, 50, 100],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
]

}]
};
return make_chart(ctx,data);
}

$(function() {
example($("#chart"));
});

谢谢

最佳答案

也许调用您的示例函数。

(function() {
example($("#chart"));
})();

关于javascript - Chart.js 在第一次加载时没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37677627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com