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

Wrong legend hitbox area when using textAlign right/center

Open adrianbrs opened this issue 1 year ago • 1 comments

Expected behavior

The entire legend item text should be clickable when centering or right-aligning the text.

For example:

Image

Current behavior

The clickable area of ​​the legend item is smaller than it should be, as if the text were always left-aligned.

Image

Also occurs in RTL mode:

Image

Reproducible sample

https://codepen.io/adrianbrs/pen/KwwzRja

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v4.4.9

Browser name and version

Google Chrome 135.0.7049.95 (64 bits)

Link to your project

No response

adrianbrs avatar Apr 22 '25 01:04 adrianbrs

hi @adrianbrs

just change this

 ` legend.legendHitBoxes.forEach((box) => {

      ctx.strokeRect(box.left, box.top, 100, box.height);//change the box.width to 100
    });`

hussainsarwari avatar Apr 26 '25 06:04 hussainsarwari