Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Cant disable `onhover` for dataset

Open batata004 opened this issue 1 year ago • 1 comments

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

batata004 avatar Jan 04 '24 18:01 batata004

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 avatar Jan 05 '24 07:01 LeeLenaleee

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

LeeLenaleee avatar Feb 04 '24 21:02 LeeLenaleee