Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chart.js library V.2将光标更改为不允许_Javascript_Chart.js - Fatal编程技术网

Javascript Chart.js library 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;

在使用Chart.js库V.2时,我想在将鼠标悬停在条形图上时将光标更改为“不允许”

这是我的密码

            // 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;}一样,整个画布将获得该属性,而不仅仅是活动图表区域。