Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show multiple tooltips #11192

Open
arnriu opened this issue Mar 17, 2023 · 2 comments
Open

Show multiple tooltips #11192

arnriu opened this issue Mar 17, 2023 · 2 comments

Comments

@arnriu
Copy link

arnriu commented Mar 17, 2023

Expected behavior

I'm trying to display multiple tooltips at once. I do not want to use chartjs-plugin-datalabels because I need to have custom labels and this is not possible with chartjs-plugin-datalabels.

Current behavior

I've came accross this issue, where someone is trying to do exactly this: #7672
It's an old issue, and it's been closed by op without good answer, so I hope it's ok to open a new issue.

I tried to make a new plugin as explained to re-use the tooltip component, and render one Tooltip per data.
And I'm stuck. The tooltips are created, but nothing shows in graph. When I log the tooltips, x, y, width and height are NaN.

I forked the example here: https://codepen.io/ariu/pen/ZEMjGLJ?editors=0010

I'm using 3.9.1 in this codepen, but I also tryied 4.2.1 locally.

Reproducible sample

https://codepen.io/ariu/pen/ZEMjGLJ?editors=0010

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

I'm trying to reproduce exactly this:

Frame 611

chart.js version

4.2.1

Browser name and version

No response

Link to your project

No response

@arnriu
Copy link
Author

arnriu commented Mar 20, 2023

I solved this hacking into tooltips externalTooltipHandler. Here is how:

  • I set the externalTooltipHandler to draw tooltips into canvas parent. But I do not override already existing tooltip. Instead, each tooltip has an ID and I only draw tooltip if the ID does not exists.
  • I have a positioner function to compute desired x and y for my element. I have a radius function to compute which corner is not rounded to make my "arrow" shape.
  • I listen to onChartReady event, and only when the animation end, I do tooltip.setActiveElements on each element I want tooltip displayed.
  • the rest is some css.

https://codesandbox.io/s/chartjs-persistent-donut-datalabels-2xomxl

@jonnybear
Copy link

Just been researching this problem. It seems crazy to me that a plugin as old and established as chartjs hasn't considered this as core functionality that is useful for practically any chart or user. All the solutions presented above by the community are impressive but far too complicated to implement this fundamental. On this basis, I am now going to look at other charting solutions, which is disappointing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants