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

Defaults tooltip option not working at all #9781

Closed
Kilazur opened this issue Oct 20, 2021 · 3 comments · Fixed by #9787
Closed

Defaults tooltip option not working at all #9781

Kilazur opened this issue Oct 20, 2021 · 3 comments · Fixed by #9787

Comments

@Kilazur
Copy link

Kilazur commented Oct 20, 2021

Expected Behavior

When setting default options for tooltips, they should be taken into account.

Current Behavior

The custom default options are completely ignored.

Possible Solution

As far as I can tell, it's either just a small overlooked issue on Chart.js's side, or I don't understand how to set these defaults. A possible solution to that would be some more "defaults configuration" examples in the documentation, because tbh this point is a little confusing :)

Steps to Reproduce

http://jsfiddle.net/a40dhzsm/1/

Context

I'm simply trying to add a "%" symbol at the end of tooltip labels.

Environment

  • Chart.js version: 3.5.1
  • Browser name and version: Firefox 93.0 / Chrome 94.0
@elinake
Copy link

elinake commented Oct 20, 2021

I'm not sure setting those as defaults is possible or optimal. When I added the options to chart it worked: http://jsfiddle.net/elinakeranen/2v31hec4/21/

options: {
         plugins: {
          tooltip: {
           enabled: true,
           intersect: false,
           mode: 'nearest',
           callbacks: {
             title: () => 'title',
             label: (item) => item.parsed + '%'
           },
         }
         }
       },

@LeeLenaleee
Copy link
Collaborator

It is possible, if you change the type to bar it works fine, reason I expect it not working for pie/doughnut charts is that chart.js overrides the default behaviour (can be seen by logging Chart.overrides.doughnut).

Guess it might be better user experience to also override the defaults if a default is set.

@etimberg
Copy link
Member

@LeeLenaleee has the correct answer. The pie/doughnut charts have overrides which are used first so the default you've specified is not used. I'm not entirely sure what the best fix is here. We could try and make the docs clearer to indicate that overrides are specified. I think it could be surprising if setting global defaults also overrode chart defaults though perhaps we could expose a method that did that for those who wanted it.

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

Successfully merging a pull request may close this issue.

4 participants