javascript - Save Client Side Generated Image on Button Click -


i have igniteui igdatachart save disk image. cannot right click on chart , save image, because uses several canvases. chart have export image method entire chart image , return javascript variable.

i automatically save file user's download folder on button click. if server side image direct user appropriate url, not.

how can user download client side generated png image of chart on button click? need crossbrowser solution.

jsfiddle

$(function () {     $("#exportbtn").click(function(){        //returns image dom element;        var pngimage = $("#chart").igdatachart("exportimage");        //now need download image     }); }); 

this solution offers better browser support , can assigned button. http://jsfiddle.net/koo2hv5t/7/

  1. check blob support (you can add message old browsers or server side fallback)
  2. wait till animation end
  3. copy chart dataurl format igdatachart
  4. convert blob util.dataurltoblob https://github.com/ebidel/filer.js
  5. save blob file saveas https://github.com/eligrey/filesaver.js

    //check support try {     var isfilesaversupported = !! new blob; } catch (e) {}  settimeout(function () {     //add data url     function downloadcanvas(link, canv, filename) {         if (isfilesaversupported) {             saveas(util.dataurltoblob(canv.src), filename);         }     }     $("#exportbtn").click(function () {         downloadcanvas(this, $("#chart").igdatachart("exportimage", 800, 600), 'test.png');     }); }, 1000); //wait till animation end 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -