Removing chart on click event produces errors
See original GitHub issueI have a click event that causes my page to change the view. The problem is that when the chart is removed it produces errors for various reasons depending on use case.
For instance this fiddle
outputs Cannot read property 'currentStyle' of null when clicking on one of the bars.
I have another use case with custom tooltips that triggers Cannot read property 'removeHoverStyle' of null
I’m sure there just need to be some null/undefined checks but not sure where to start looking and was hoping someone could provide some guidance.
Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Removing chart on click event produces 'removeHoverStyle' of ...
I am on react 16.12 with react-chartjs-2 2.9.0 . I have found that the chart itself has the property "onElementsClick" that you can...
Read more >Removing chart on click event produces 'removeHoverStyle' of ...
I am on react 16.12 with react-chartjs-2 2.9.0 . I have found that the chart itself has the property "onElementsClick" that you can...
Read more >Add, change, or remove error bars in a chart - Microsoft Support
Click the Chart Elements button Chart Elements button next to the chart, and then check the Error Bars box. (Clear the box to...
Read more >How to add error bars in Excel: standard and custom - Ablebits
Add error bars to your chart as usual. · Right-click any vertical error bar and choose Delete from the pop-up menu. Delete vertical...
Read more >How to Write an Action Listener
In the above example, the event handler class is AL which implements ActionListener. We would like to handle the button-click event, so we...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

My wrapper chart looks like this
In my options object that I pass in, I have an onClick callback function that changes one of the parent’s state variables (a boolean). This boolean renders another chart if true and removes the current chart
Parent.js
I seem to be getting this error when isTrue is changed to false and the first Barchart is unmounted. The removeHoverStyle gets called for some reason @ryan-morris
I’ve also posted on stackoverflow: https://stackoverflow.com/questions/57314992/removing-chart-on-click-event-produces-removehoverstyle-of-null-error
@aemc I’m not very familiar with react. Depending on how your chart is removed, you may be able to destroy the chart in the
componentWillUnmountof its parent. The overall idea being to tap into an event available in react that lets you know just prior to it being removed from the DOM