I want to show a graph in a modal window when the user clicks a button. The modal is hidden with display: none;
, and becomes visible with display: flex;
once the button is clicked.
If I move the chart outside of the modal, it works without any issues.
Adjusting the height of the chart from 0px in dev tools makes it appear correctly.
To demonstrate the problem, I created a codepen. You can see the issue by commenting/un-commenting the code inside or outside of the modal.
The code for the graph is borrowed from another example on CodePen that I came across.
Although I found a helpful answer on StackOverflow, implementing the solution into my own code has proved difficult. Here's the advice I received:
"It seems like the canvas and all its parent nodes cannot be set to display none at the time the chart call is made. If you're using a chart in a popup, you should first display the popup, create the chart, and then hide the popup."