title: How to get background color of SVG converted properly into Canvas
body: <p>Im converting a d3 svg object with use of canvg library to an canvas and display it as an image (png).</p>
  
  <p>The resulting image has a transparent background, which is not what I want. I need this with a white background.</p>
  
  <p>So i tried to set the background color of svg element. When viewing svg element it is fine, but the converted image is still transparent.
  I also tried, to alter background of the canvas object, but this is also not working.</p>
  
  <p>first approach (svg):</p>
  
  <pre><code>var svg = d3.select(".chart").append("svg").attr("style","background: white;")...
  </code></pre>
  
  <p>second aproach (canvas):</p>
  
  <pre><code>canvg(document.getElementById('canvas'), $("#chart").html());
  
  var canvas = document.getElementById('canvas');
  canvas.style.background = 'white';
  var img = canvas.toDataURL('image/png');
  document.write('&lt;img src="' + img + '"/&gt;');  
  </code></pre>
  
  <p>Does anyone know, on which object I have to set the background color, in order to get it converted properly in png image ? </p>
  
  <p>Edit: With the information mentioned in ThisOneGuys answers, I found this solution.</p>
  
  <pre><code>var svg = d3.select(".chart").append("svg") ...
  
  svg.append("rect")
  .attr("width", "100%")
  .attr("height", "100%")
  .attr("fill", "white"); 
  </code></pre>
  
  <p>With the appended rect, I get what I need :)</p>