I am using jQuery flot graph and want to take the print out (or at least the image) of the graph. Now, before asking this question I did lot of research to find out a way..and I come up with this question on stack overflow.
I implemented the technique given there.
Now, I am able to get the image of the graph but I am not able to get the contents of the graph i.e. I am just getting plain background of the canvas and not the area drawn over it.
The images below will explain this clearly:
This is what my graph looks like...
And this is what I am getting after coverting it to image:
I am using the ToDataUrl
for coversion and below is my code:
var somePlot = $.plot("#placeholder", [ [0,0],[10,10] ]);
var canvas = somePlot.getCanvas();
var img = canvas.toDataURL("image/png");
document.write('<img src="'+img+'"/>');
In the code above:
somePlot
variable is for fetching the canvas which is inside the div
as jquery flot
implements the graph inside a canvas which I was not able to access directly using its id
.
Any help will be appreciated, Thankyou...