How to print flot graph

Abhinav picture Abhinav · Nov 23, 2011 · Viewed 7.4k times · Source

Can any body help me to find out, how to print dynamic graph as example generated by flot. I tried this one but it's printing whole page, but I want only graph portion.

function printGraph(){
    $('<img src="../images/button_refresh.png" alt="Print Graph" style="">').appendTo(controlholder).click(function (e) {                        
        //Canvas2Image.saveAsPNG(document.getElementById('placeholder'));
        //canvas.toDataURL("image/png");
        window.print('placeholder');
    });
}

Answer

Raidri supports Monica picture Raidri supports Monica · Aug 6, 2013

This article describes how to copy the canvas to a normal img which can then easily be printed or saved as an image.

The important part:

img.src = canvas.toDataURL();

See the great answer below from Ignacio Correia for more details.