Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When you visit the site, paste this in the console (overwriting the malfunctioning function).</p> <pre><code> function getImgData(chartContainer) { var chartArea = chartContainer.getElementsByTagName('svg')[0].parentNode; var svg = chartArea.innerHTML; var doc = chartContainer.ownerDocument; var canvas = doc.createElement('canvas'); canvas.setAttribute('width', chartArea.offsetWidth); canvas.setAttribute('height', chartArea.offsetHeight); canvas.setAttribute( 'style', 'position: absolute; ' + 'top: ' + (-chartArea.offsetHeight * 2) + 'px;' + 'left: ' + (-chartArea.offsetWidth * 2) + 'px;'); doc.body.appendChild(canvas); canvg(canvas, svg); var imgData = canvas.toDataURL("image/png"); canvas.parentNode.removeChild(canvas); return imgData; } </code></pre> <p>In JS it was searching for an iframe bla bla to get the svg.</p> <p><br/> To automatically save the image, you can just let the method being invoked programmatically.</p> <pre><code>document.body.addEventListener("load", function() { saveAsImg( document.getElementById("pie_div")); // or your ID }, false ); </code></pre> <p><br/> For saving images serverside, this post could be helpful <a href="https://stackoverflow.com/questions/11511511/how-to-save-a-png-image-server-side-from-a-base64-data-string#answer-11511552">save a PNG image server-side</a></p> <p><strong>Update</strong><br/> Posting images to PHP (index.js)</p> <pre><code>function saveToPHP( imgdata ) { var script = document.createElement("SCRIPT"); script.setAttribute( 'type', 'text/javascript' ); script.setAttribute( 'src', 'save.php?data=' + imgdata ); document.head.appendChild( script ); } function save() { var canvas = document.getElementById("canvas"), // Get your canvas imgdata = canvas.toDataURL(); saveToPHP( imgdata ); } function drawOnCanvas() { var canvas = document.getElementById("canvas"), // Get your canvas ctx = canvas.getContext("2d"); ctx.strokeStyle = "#000000"; ctx.fillStyle = "#FFFF00"; ctx.beginPath(); ctx.arc(100,99,50,0,Math.PI*2,true); ctx.closePath(); ctx.stroke(); ctx.fill(); } drawOnCanvas(); // Test save(); </code></pre> <p>save.php</p> <pre><code>&lt;?php // Get the request $data = $_GET['data']; // Save to your DB. ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload