Possible with a tooltip for labels? #748
Replies: 10 comments
-
The only workaround I can think of for this is to use the onMouseover event to set the content of an external div:
Maybe there is a better way? |
Beta Was this translation helpful? Give feedback.
-
We ended up implementing something that worked with Charjs3.5 and the most recent annotation version 1.0.2 (as of 8/6/2021). The jist is that we create the annotation object and attach it to the window, within that we have a Below is a full working sample, see the A full working sample is:
I hope this is helpful, not sure I'll stay on top of more recent releases in either package, but I'm willing to help if I can for anyone struggling. Keep in mind, annotation lastly, my apologies if some of the js is not syntactically correct, I've adapted this from our production code which was not github-ready. |
Beta Was this translation helpful? Give feedback.
-
@Djones4822 Thanks a lot ! Your solution is perfect for me. I just made little changes to your function :
|
Beta Was this translation helpful? Give feedback.
-
I needed to display big texts and annotation labels do so shitty job here.
I considered several solutions.
So I followed the third approach. The idea is to show a basic annotation label and display all the data in the tooltip. I don't need to manage responsiveness, or support a code. It is elegant and cheap. So just add this to your options and place some business logic to display a content that you want.
Hope this will save some time for you, future reader! |
Beta Was this translation helpful? Give feedback.
-
@artemdumanov thank you very much! Anyway, and correct me if I'm wrong, I think that solution is working only if the annotation is intersecting the data element. |
Beta Was this translation helpful? Give feedback.
-
Is there any solution for adding a tooltip if the annotation is NOT intersecting the data element? |
Beta Was this translation helpful? Give feedback.
-
@joeboe17 I had time to have a look to your use case. I have prepared a codepen: https://codepen.io/stockinail/pen/dyZdMmq Few info: the enter callback of line annotation is getting the nearest dataset element to the line but of course you can take the dataset element you need, by ChartJs API. Hopefully can help. |
Beta Was this translation helpful? Give feedback.
-
@kurkle @LeeLenaleee I was thinking if the above use case can have space among the samples in the documentation. It's anyway a complex and special use case and maybe it doesn't make sense. |
Beta Was this translation helpful? Give feedback.
-
Complexity is doable (in its current form) thats not an issue here in my oppinion. The biggest issue that I see with this example is that it is kind of misleading. For the X axis you show the april month, since its a category axis I can get behind that, that you take the one that is closest but that it shows a y axis value of 15 does feel weird. Would expect to see 17.5 since it intersects there. Adding this will add a nice bit of complexity. Also this does feel like a verry specific use case, if more people have issues like this we can always add it, but I think the less custom code the better. Even if its not that complex |
Beta Was this translation helpful? Give feedback.
-
Might be doable with a custom interaction mode that is also considering annotations. That said, I don't think we should make this a "supported" use case at this time, so I vote no for an sample. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a line chart with vertical annotations and a label on top.
I would have been great to have a tooltip on this label, i have looked around, but i have not found that this feature is included in this plugin. Is this correct, is it not possible for the moment with tooltips for annotation labels?
Beta Was this translation helpful? Give feedback.
All reactions