我尝试在chart.js圆环图中调用函数getElementsAtEventForMode()
,但我在控制台中不断收到此错误消息:chart.getElementsAtEventsForMode is not a function
.
// Pass the canvas ID
let myChart = Chart.getChart('myChart');
//updating chart with new values each time a value is selected
if (myChart) {
myChart.data.labels = legend;
myChart.data.datasets[0].data = stats;
myChart.config.options.plugins.title.text = "Top 5 causes of death in " + country;
myChart.update();
} else {
new Chart('myChart', config);
}
//detecting click on doughnut sections for modal
this.clickHandler = function (onclick) {
const points = myChart.getElementsAtEventForMode(onclick, 'nearest', { intersect: true }, true);
if (points[0]) {
modal.classList.toggle('hide');
}
}
addEventListener("click", this.clickHandler);
2条答案
按热度按时间7ivaypg91#
您不能使用全局图表示例,需要使用图表示例来调用函数,如下所示:
5t7ly7z52#
在Chartjs中,它具有getElementsAtEventForMode,而不是事件ForMode ..使用
而不是