onHover 事件未在 chart.js 中触发
onHover event is not triggering in chart.js
我想当鼠标在图表上移动时改变光标,比如this fiddle。
这适用于 chart.js v2.4
但不适用于 v2.6
& v2.7
有什么想法吗?
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", e[0] ? "pointer" : "default");
/* without jquery it can be like this:
var el = document.getElementById("canvas1");
el.style.cursor = e[0] ? "pointer" : "default";
*/
}
}
}
});
从 v2.5
起,onHover 回调的参数已更改。参见 PR#3669
onHover callback now has 3 parameters. The 2nd parameter is the event
that triggered the hover. This was done for consistency with the
onClick callback.
function(event, activeElements) {
}
之前,activeEvents 是第一个参数,event 没有传递。
因此您必须按如下方式更改 onHover callback
:
onHover: function(event,elements) {
$("#canvas1").css("cursor", elements[0] ? "pointer" : "default");
}
我想当鼠标在图表上移动时改变光标,比如this fiddle。
这适用于 chart.js v2.4
但不适用于 v2.6
& v2.7
有什么想法吗?
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", e[0] ? "pointer" : "default");
/* without jquery it can be like this:
var el = document.getElementById("canvas1");
el.style.cursor = e[0] ? "pointer" : "default";
*/
}
}
}
});
从 v2.5
起,onHover 回调的参数已更改。参见 PR#3669
onHover callback now has 3 parameters. The 2nd parameter is the event that triggered the hover. This was done for consistency with the onClick callback.
function(event, activeElements) {
}
之前,activeEvents 是第一个参数,event 没有传递。
因此您必须按如下方式更改 onHover callback
:
onHover: function(event,elements) {
$("#canvas1").css("cursor", elements[0] ? "pointer" : "default");
}