Open ldhasson opened 4 months ago
As I can read in the documentation about the offsetTop
property, it returns the offset to the closest anchor element. In this case its the TD
. Because of this in both the charts it will return 1
as the offset. To get the accurate position you will need to use getBoundingClientRect
on the client. If you use that you get the real position and then you can feed the y and x coordinates of those to the position of the tooltip and that will work fine.
Agreed, but the documentation and sample are not so clear about this. This works for a general tooltip DIV attached at the document level and with position:relative. The positioning then works anywhere everywhere all at once.
Expected behavior
No matter where a chart is positioned, correct coordinates should be available for the tooltip implementation (with respect to the viewport?).
Current behavior
chart.canvas.offsetLeft and chart.canvas.offsetTop etc... have values representing the relative positioning of the chart within the table element.
Reproducible sample
https://www.chartjs.org/dist/master/chart.umd.js
Optional extra steps/info to reproduce
Possible solution
No response
Context
We are trying to use ChartJS in an environment where lots of HTML tables are used. We can figure out some work arounds, but painful. In general though, for tooltips, we should be able to get viewport-relative coordinates.
chart.js version
v4.2.1
Browser name and version
Firefox and Chrome (latest) on Windows 11
Link to your project
No response