2

I have an application which uses jqplot to produce some graphs I want to have the ability to print the graph, and only the graph.

So I wrote a function a simple function that opens a new window containing the code from the graphdiv in the main page of the application. My problem is that the graph does not display properly in the new window. Any ideas??

function newwindow() {

    var windowObject = window.open('', 'windowObject', 'arguments...');
    windowObject.document.write("<html> <head><link rel='stylesheet' type='text/css' href='jquery.jqplot.css' /></head> <body onload=''><div class='jqplot-target'>" + $('#chartdiv').html() + "</div></body></html>");
    windowObject.document.close();


}

Thanks.

dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
eshepard
  • 57
  • 1
  • 9
  • What does "not display properly" mean? From the code it looks like you are grabbing the html from previously rendered plot and throwing it into your new window. I think this will only get you the canvas element but not what was drawn on the canvas. See this question: http://stackoverflow.com/questions/3318565/any-way-to-clone-html5-canvas-element-with-its-content – Mark Feb 28 '12 at 18:08
  • Mark, I think that's right. I was grabbing the html of a previously rendered plot assuming that that this would copy everything. – eshepard Feb 29 '12 at 01:40

1 Answers1

0

Create a function like this so that the opened image will have a dataUrl.

var img = $('#chartdiv').jqplotToImage(50, 0);
  if (img) {
    open(img.toDataURL("image/png"));
  } 

This jqplot to image can be found in this link https://github.com/lsiden/export-jqplot-to-png

Juliyanage Silva
  • 2,529
  • 1
  • 21
  • 33