Javascript Chart.js library V.2将光标更改为不允许
在使用Chart.js库V.2时,我想在将鼠标悬停在条形图上时将光标更改为“不允许” 这是我的密码Javascript Chart.js library V.2将光标更改为不允许,javascript,chart.js,Javascript,Chart.js,在使用Chart.js库V.2时,我想在将鼠标悬停在条形图上时将光标更改为“不允许” 这是我的密码 // Draw Chart var ctx = document.getElementById("main").getContext("2d"); ctx.canvas.width = calculatedWidth; ctx.canvas.height = calculatedHeight || 400;
// Draw Chart
var ctx = document.getElementById("main").getContext("2d");
ctx.canvas.width = calculatedWidth;
ctx.canvas.height = calculatedHeight || 400;
mainDashboardChart = new Chart(ctx, {
type: 'bar',
data: dashboardDatas,
yLabels: 0,
options: dashboardOptions('noSubChart', suggestedMaxVal, subChartDataLength)
});
我找不到这样做的方法。有人知道这是否可行吗?您将能够使用
getElementAtEvent
方法获取活动点
因此,代码将是
var helpers = Chart.helpers;
helpers.bindEvents(mainDashboardChart, ["mousemove", "touchstart", "touchmove", "mouseout"], function(evt){
var activeElement = mainDashboardChart.getElementAtEvent(evt);
$('#main').css('cursor',activeElement.length ? 'not-allowed' : 'default'); });
您可以像这样使用
悬停
选项:
hover: {
onHover: function(e) {
$("#myChart").css("cursor", e[0] ? "pointer" : "default");
}
}
甜甜圈图表上的工作示例:您是否尝试过使用CSS进行此操作?像#main{cursor:notallowed;}一样,整个画布将获得该属性,而不仅仅是活动图表区域。