gpt4 book ai didi

javascript - 将 mouseout 事件处理程序添加到 Chart.js 中的图例

转载 作者:行者123 更新时间:2023-11-29 10:05:24 24 4
gpt4 key购买 nike

在图例的 onHover 事件中,我想将鼠标光标的样式更改为指针(是的,这可以按照下面的代码来完成)。但是如果鼠标超出图例,我想将鼠标光标更改回默认值。在 Chart.js 中有可能吗?谢谢。

注:在Chart.js documentation它提供 onHover 回调,但没有 mouseout。

HTML:

<canvas id="canvas1" height="150"></canvas>

JavaScript:

var ctx = document.getElementById("canvas1").getContext("2d");

var mychart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['uno', 'dos', 'tres', 'cuatro'],
datasets: [{
data: [1, 2, 3, 4],
backgroundColor: ["#BDC3C7","#9B59B6","#E74C3C","#26B99A"]
}]
},
options: {
legend: {
position: 'bottom',
onHover: function(c) {
console.log(c);
$("#canvas1").css("cursor", "pointer");
}
},
}
});

这是 the example in jsfiddle 的链接.

最佳答案

添加这个

hover: {
onHover: function(e) {
$("#canvas1").css("cursor", "auto");
}

选项:


像这样:

var ctx = document.getElementById("canvas1").getContext("2d");

var mychart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['uno', 'dos', 'tres', 'cuatro'],
datasets: [{
data: [1, 2, 3, 4],
backgroundColor: ["#BDC3C7","#9B59B6","#E74C3C","#26B99A"]
}]
},
options: {
hover: {
onHover: function(e) {
$("#canvas1").css("cursor", "auto");
}
},
legend: {
position: 'bottom',
onHover: function(c) {
console.log(c);
$("#canvas1").css("cursor", "pointer");
}
}
}
});

https://jsfiddle.net/v77twcww/

关于javascript - 将 mouseout 事件处理程序添加到 Chart.js 中的图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44572474/

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