Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print flot graph

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');
    });
}
like image 779
Abhinav Avatar asked Nov 23 '11 12:11

Abhinav


1 Answers

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.

like image 111
Raidri Avatar answered Sep 30 '22 18:09

Raidri