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.
$(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/
- check blob support (you can add message old browsers or server side fallback)
- wait till animation end
- copy chart dataurl format
igdatachart - convert blob
util.dataurltoblobhttps://github.com/ebidel/filer.js save blob file
saveashttps://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
Post a Comment