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');
});
}
Launch a new window with only the graph or with alternate css similar to what google maps does when you print.
Found a solution by using html2canvas. First assign the container div to have id like "theChart".
Now we can create an image:
This will also solve the problem when
canvas.toDataURL()
does not render axis labels.This article describes how to copy the
canvas
to a normalimg
which can then easily be printed or saved as an image.The important part:
See the great answer below from Ignacio Correia for more details.
You could hide the parts of the page you don't wish to print by using a separate stylesheet that has
media="print"
. This would also allow you to tweak the final printed output of the graph itself, for example making it larger.Attention this post have been edited, please see all possible solutions
From what I have searched and found you have only 2 choices or try to print the CANVAS, or EXPORT as an image or my idea is to separate the image from the content and try to print only the graph. Here is a FAQ by Flot, how can you export the image: Question Number 3
SOLUTION 1 - Export image:
Export image to computer and then print it
SOLUTION 2 - FLOT to CANVAS:
SOLUTION 3 - My own, Modal printing
This is not the best solution by far but it works, here is a demo:
Steps
Here is the necessary code:
Extra This related question is about exporting Flot to PDF, don't know if you may be interested: Export Flot to PDF
EDIT - WORKING SOLUTION Here is a working demo of how to export the image: FLOT to IMAGE