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
Get other annotations width from an annotation scriptable option. #865
Comments
@evenmind the width of an annotation is a property of the annotation elements which are NOT exported (and then NOT exposed). |
@stockiNail thank you for fast reply. |
If you have to add more than 2 labels, it's not possible, because the position option enable you to decide, depending the point, if you want the label all on the right or on the left (or top or bottom).
As said, the x, y, x2, y2, width, height, centerX and centerY are all properties of the annotation elements which are not officially exposed. :( In the next version, there will be 2 new hooks which can help you on that: #744 Setting the z options (to be sure that the labels are draw in the right order), you could take the width (storing it in a variable) and change accordingly all the other labels (accessing to the element). |
Anyway, even accessing to the loaded elements, you don't know the width of the label you want to change therefore it's quite difficult I guess. |
I will check the private state in the meantime the next version is live, thanks. |
I think we could add the loaded elements to the element context in order to address this use case (and also others). |
I get undefined for |
Can you provide a sample to reproduce the issue? |
I literally just
and get undefined. Maybe this is because I'm using vue-chartjs wrapper and it does not inject 'chartjs-plugin-annotation' in the window ? |
Yes, I think so. I think you are importing the plugin, something like:
If yes, use |
Works ! Thank you. |
@evenmind just FYI, I have submitted a PR #869 which is adding the elements to the context. In this way, you will not need to use the undocumented API but you can use the elements in the context. |
Hey, thank's for this usefull plugin !
I would like to get the width of an annotation from within another annotation scriptable option (to place the 2nd annotation next to the first relative to the width of the 1st annotation).
I want to accomplish something like that:
But the problem is ctx.chart.options.plugins.annotation.annotations.annotation1.width doesn't exists.
Is it possible to achieve ?
Thanks in advance.
The text was updated successfully, but these errors were encountered: