Display none to block, graph is empty

Hi Team,

I don’t want to show the graph by default, but want to make some API calls ( for graph data) on page load.
If I click on the show graph button, I am changing the display property from none to block.
But the graph loads up empty.
Works fine if I don’t hide the graph.
I know the display:none turns off the layout of the elements, so they are not rendered which causing this issue.
Any way to get around this issue?

Thanks,
Aishwarya

Can you hide it by placing the HTMLDivElement outside of the flow of the page, where people cannot see it or scroll to it?