如果图例悬停,我想将鼠标光标的样式更改为指针(是的,这可以按照下面显示的代码来完成(。但是如果鼠标超出图例,我想将鼠标光标更改回默认值。在图表.js中可能吗?谢谢。
注意:在图表.js文档中,它提供了悬停回调,但没有鼠标退出。
.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");
}
},
}
});
这是jsfiddle中示例的链接。
添加这个
hover: {
onHover: function(e) {
$("#canvas1").css("cursor", "auto");
}
到options:
喜欢这个:
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/