Search code examples
javascriptd3.jstooltip

Show a D3 SVG Within a Tooltip


I have the following jsfiddle: http://jsfiddle.net/nxC7d/1/

When you click on the span element, its text is parsed as YAML, and the resulting data is used to create a pie chart via D3. My issue is that the pie chart svg element is currently just inserted into the body, and I would like it to appear in a tooltip when the span is clicked.

What is the best way to accomplish this?


Solution

  • Make the tooltip a floating div (i.e. position fixed) and append the SVG to that. Also, keep a reference to the SVG so that you can reuse it and don't create a new one on each click.

    Complete example here. This can obviously be made fancier, but it should get you started.