-
Notifications
You must be signed in to change notification settings - Fork 331
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
Annotation event not updating with Chart.js 2.7 #88
Comments
You will need to call |
Actually I did try this after looking at that example and some other comments. However my problem still persists. I reproduced the example you offer directly with the same errors as I receive in my own chart. Could this be some other kind of dependency? I use Mac Os Sierra and tested in Chrome and Safari and no browser showed me annotations reacting to events. |
@attack68 have you tried the example I linked to to see if it works in your environment? What version of chartjs-plugin-annotation and chart-js are you using? |
Also what version of Chrome are you running? Can you go to chrome://flags and check your "Passive Event Listener Override" option (make sure it is set to Default)? |
Yes I took the code you supplied in the link and substituted only two lines (the script sources): I experience the same issue in Firefox and Safari, running Mac Os Sierra. I experience the issue on two separate Macs. |
@attack68 Can you try downgrading to Chart.js 2.5? |
Just downgraded, annotation events works with 2.5.0. |
You can turn off the line, see the Chart.js documentation. |
This also happens to me. This is what I using to generate chart.
After I change my chart.js lib from v-2.7 to v-2.5, it works as I expected. :) |
Bump! This is forcing me to use 2.5 while I would need some features from the 2.7 as well. |
@compwright any update on this issue? because i am having a problem. in updating. |
@compwright I am also having same problem and downgrading to chart.js to 2.5.0 made my annotations totally disappear. |
I'm not actively using this at this time with any of my projects and would welcome help if anyone wants to submit a pull request to update this plugin to work with 2.7. I'll get to it when I can, but I can't tell you when that will be. |
@compwright i am quite new to the javascript and did not know much, so that i can go through the source files. I would love to help in this regard. If you can tell what problem should actually be in this problem may be i can dig in and can help you. I am a regular user of these plugins and chartjs and would love to help in this regard. |
Hi all, I have able to make it work by destroying and creating chart again. |
I was able to work around this problem. Upon inspecting the Charts options, it looks like something has changed in Chart.js where it is coping the annotations array making it inaccessible from the annotations plugin. Aka, you try to add line into the annotations array and it doesn't appear in the charts options.annotations array. To work around this I had to use something like this. . . Chart.helpers.each(Chart.instances,(instance) => { rather than doing something like this. . . annotations = [{. . .}] It seems that this pass by reference approach doesn't work and you have to modify the property directly on the chart instance. I tried to look at the annotations code to fix this but it's beyond me. Hopefully this work around at least helps people use chart.js 2.7.x until the author of this library gets a patch in place. |
Quick update here. I believe I have tracked the problem to chartjs and some work that was done leading up to 2.7.x release. At this point I'm not convinced it's a problem with this plugin, but rather something that needs to be fixed/weighed in on by the chartjs team. For details of my findings please refer to this link. chartjs/Chart.js#5111 |
@compwright Per the thread I have opened with the chart.js team, I think some of the sample files need to be updated. I also think that you should put a section on the front page of the annotation as well as the draggable plugins github page stating that if someone is upgrading from 2.x to 2.7.x that they will likely need to change how/where they are populating the annotation data and getting it onto the chart object. I'm happy to update the sample files, but I'm not sure what kind of process I would need to follow to update the front page. Is this something you can do for me if I type up the verbiage? |
@nullpointer77 you can update it by making a pull request with your changes to README.md. Thanks! |
I'm trying to understand if this issue is what I'm experiencing.
But the line doesn't move, just stays at the original value. Is this issue representative of what I'm trying to do and it not working? |
yes this is the same problem listed above. The ChartJS team has changed how this stuff works and arrays are copied around internally rather than by reference. If you want further assistance please put a JSFiddle example of this out there and I can look. |
Here is a fiddle of what I'm trying to accomplish. You get the initial vertical line at 5. Only way I see to do it right now is destroy and recreate the entire chart. Thanks. |
Please find a work around here. I'm not quite sure why but it looks like giving the annotation an ID really screws things up. I removed that and it seemed to work correctly. Sorry for the delay on this.
|
Thanks @nullpointer77 , I had the same problem and removing the "id" attribute solved it. |
I'm not sure what that line in the link below actually does, but with 2.7.2 ChartJS it causes the error from the original post. https://github.com/chartjs/chartjs-plugin-annotation/blob/master/src/events.js#L96 |
Note: @osro wrote chartjs-plugin-annotation/src/events.js Line 96 in 1643f3c
|
@nullpointer77 wrote:
I had a different issue - need to display a tooltip only when hovering the annotation, and the mouse events didn't seem to respond correctly.
|
Hi,
where annotations are the array with annotations options. |
Can confirm that the solution @RieseIch proposed works. |
I believe this is resolved in v3.0.0-beta.12 because we changed how options are resolved to avoid merging (and thus changing the underlying arrays). I tested the update sample and it works fine with v3. |
It is entirely possible this is a bug with my code and understanding rather than the tool itself as it is very new to me,
I am using the following code to roughly test the tooltip hover mechanics for an annotation label:
the console shows the label.enabled property changing from false to true, but the chart doesn't display a change. I have tried linking with this.chartInstance.update() but still doesn't work.
The JS console error I receive is:
Unable to preventDefault inside passive event listener invocation.
dispatcher @ chartjs-plugin-annotation.js:261
I'll attempt to provide demo unless you quickly spot a mistake I'm making.
The text was updated successfully, but these errors were encountered: