大家下午好。我正在尝试在同一页上使用两个图表。它正在工作,但我仍然在我的控制台日志中得到一个错误:
Uncaught Error: Canvas is already in use. Chart with ID '1' must be destroyed before the canvas with ID 'rankingsActive' can be reused.
我的HTML
<div>
<canvas id="rankings" ></canvas>
</div>
<div>
<canvas id="rankingsActive"></canvas>
</div>
我的javascript代码。我将发布创建我的第一个图表的第一个函数。我有一个类似的函数,唯一的区别是最后一行。不同的图表名称和目标我的第二个画布ID
function rankingTypes(ranks) {
//const labels = ["January", "February", "March", "April", "May", "June"]
const data = {
labels: Object.keys(ranks),
datasets: [
{
label: "My First dataset",
backgroundColor: "rgb(255, 99, 132)",
borderColor: "rgb(255, 99, 132)",
data: Object.values(ranks),
},
],
}
console.log(data)
console.log(Object.values(ranks))
const config = {
type: "pie",
data: data,
}
const rankChart = new Chart(document.getElementById("rankings"), config)
}
1条答案
按热度按时间iaqfqrcu1#
这意味着您已经在该画布上制作了一个图表,因此您必须先销毁该图表。可以这样做: