title: How to add an image to an svg container using D3.js
body: <p>I've created a sample Asp.Net MVC 4 application where I've used D3.js to append an SVG element and then inside the SVG I've appended a text element (see code below).  This all works fine until I try to append an img to the SVG using a local png file.  The img gets appended to the DOM, but the img is not rendered on the page.  Any ideas what I'm doing wrong here, and how to go about fixing it?</p>
  
  <pre><code>@{
      ViewBag.Title = "Home Page";
  }
  
  &lt;script src="~/Scripts/d3.v3.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      var svg = d3.select("body")
          .append("svg")
          .attr("width", 200)
          .attr("height", 100)
          .style("border", "1px solid black");
  
      var text = svg.selectAll("text")
          .data([0])
          .enter()
          .append("text")
          .text("Testing")
          .attr("x", "40")
          .attr("y", "60");
  
      var imgs = svg.selectAll("img").data([0]);
      imgs.enter()
          .append("img")
          .attr("xlink:href", "@Url.Content("~/Content/images/icons/refresh.png")")
          .attr("x", "60")
          .attr("y", "60")
          .attr("width", "20")
          .attr("height", "20");
  
  &lt;/script&gt;
  </code></pre>
  
  <p>@Richard Marr - Below is an attempt to do the same thing in straight HTML, which gives me the same result.  I'm not sure about my code to get the refresh.png file from the local drive this way.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;script src="http://d3js.org/d3.v2.js"&gt;&lt;/script&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;script type="text/javascript"&gt;
              var svg = d3.select("body")
                  .append("svg")
                  .attr("width", 200)
                  .attr("height", 100)
                  .style("border", "1px solid black");
  
              var text = svg.selectAll("text")
                  .data([0])
                  .enter()
                  .append("text")
                  .text("Testing")
                  .attr("x", "40")
                  .attr("y", "60");
  
              var imgs = svg.selectAll("img").data([0]);
                  imgs.enter()
                  .append("svg:img")
                  .attr("xlink:href", "file:///D:/d3js_projects/refresh.png")
                  .attr("x", "60")
                  .attr("y", "60")
                  .attr("width", "20")
                  .attr("height", "20");
  
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>