Skip to content Skip to sidebar Skip to footer

On Button Click Open A New Window And Draw A Circle With D3

I'm trying to open a new window on button click and draw a simple circle on it. I can open a window but circle won't appear on it with this code. Any ideas on how to solve this.0

Solution 1:

When you call drawBarChart(newWindowRoot), you're passing a d3 selection — the result of d3.select(newWindow.document.body) — into that function. That makes sense.

However, from within drawBarChart, you call var sampleSVG = d3.select(newWindowRoot), essentially making a d3 selection of a d3 selection. That doesn't work (unlike what you might expect from jQuery). You should skip that latter d3.select and that'll make your code begin to work. More specifically, that'll make the button appear in the new window, but not the circle.

To make the circle appear, you need to fix another issue: Your fiddle attempts to add the circle to the button, instead of to an SVG (this is different than your example above which isn't trying to create a button).

Here's a working fiddle

By the way, the reason the jsFiddle you linked to didn't work is because the link you embedded was using secure protocol (https) and the jsfiddle functionality that was trying to load d3 is insecure (http), which resulted in a failure to load d3 and in turn an error executing your code.

Post a Comment for "On Button Click Open A New Window And Draw A Circle With D3"