Chart.JS 条形图的 mousein 和 mouseout 事件?
Event on Chart.JS's Bar Chart's mousein and mouseout?
我已经搜索了 bar chart and event 文档(我发现它有点令人困惑)并且我一直无法弄清楚将鼠标悬停在条形图的条上时如何处理 mousein 和 mouseout 事件(不是传说!)。目前我能做到的最接近的是像这样利用工具提示上的回调:
options.tooltips = {
backgroundColor: 'rgba(0,0,0,0)',
fontColor: 'rgba(0,0,0,0)',
callbacks: {
label: function (tooltipItem) {
// flipping a bool here
}
}
};
此解决方案效果不佳,因为不知道指针何时离开栏我不知道何时将布尔翻转回来。这可能吗?
这是我的问题的解决方案:
options.tooltips = {
// Hide the tooltips
backgroundColor: 'rgba(0,0,0,0)',
displayColors: false,
callbacks: {
labelTextColor: function () {
return 'rgba(0,0,0,0)';
},
labelColor: function () {
return {
borderColor: 'rgba(0, 0, 0, 0)',
backgroundColor: 'rgba(0, 0, 0, 0)'
}
}
},
// Highlight the HTML elements on bar hover
custom: function(tooltipModel) {
if (tooltipModel.body === undefined) {
// flip bool false
return;
}
if (/* ... */) {
// flip bool true
}
return;
}
};
我已经搜索了 bar chart and event 文档(我发现它有点令人困惑)并且我一直无法弄清楚将鼠标悬停在条形图的条上时如何处理 mousein 和 mouseout 事件(不是传说!)。目前我能做到的最接近的是像这样利用工具提示上的回调:
options.tooltips = {
backgroundColor: 'rgba(0,0,0,0)',
fontColor: 'rgba(0,0,0,0)',
callbacks: {
label: function (tooltipItem) {
// flipping a bool here
}
}
};
此解决方案效果不佳,因为不知道指针何时离开栏我不知道何时将布尔翻转回来。这可能吗?
这是我的问题的解决方案:
options.tooltips = {
// Hide the tooltips
backgroundColor: 'rgba(0,0,0,0)',
displayColors: false,
callbacks: {
labelTextColor: function () {
return 'rgba(0,0,0,0)';
},
labelColor: function () {
return {
borderColor: 'rgba(0, 0, 0, 0)',
backgroundColor: 'rgba(0, 0, 0, 0)'
}
}
},
// Highlight the HTML elements on bar hover
custom: function(tooltipModel) {
if (tooltipModel.body === undefined) {
// flip bool false
return;
}
if (/* ... */) {
// flip bool true
}
return;
}
};