chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.5k stars 11.89k forks source link

Cant disable `onhover` for dataset #11628

Closed batata004 closed 8 months ago

batata004 commented 9 months ago

Expected behavior

It should disable

Current behavior

It is not being disabled

Reproducible sample

onhover return is not being honored

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

The code below should disable the hover effect for all the datasets except 1. However it has no effect.

                onHover:function(evt,activeEls,chart) {

                    console.log(evt,activeEls,chart);
                    if (activeEls.datasetIndex === 1) {

                        return true;

                    }
                    else{

                        return false;

                    }

                },

chart.js version

latest

Browser name and version

chrome latest

Link to your project

No response

LeeLenaleee commented 9 months ago

If you want your onHover function to only work for 1 dataset you need to write it like this:

onHover:function(evt,activeEls,chart){
                    if (activeEls.datasetIndex !== 1) {

                        return;

                    }
                    // Your actual code

                },
LeeLenaleee commented 8 months ago

Closing as this is not a bug, just a wrong implementation