Print Dygraph chart

2019-08-05 19:25发布

问题:

I'm trying to print a Div, containing a dygraph as follows:

javascript:

<script type="text/javascript">
            function PrintElem(elem)
            {               
                Popup(document.getElementById(elem).innerHTML);
            }

            function Popup(data) 
            {
                var mywindow = window.open('', 'my div', 'height=400,width=800');
                mywindow.document.write('<html><head><title>my div</title>');                
                mywindow.document.write('</head><body >');
                console.log(data);
                mywindow.document.write(data);
                mywindow.document.write('</body></html>');

                mywindow.print();
                mywindow.close();

                return true;
            }    
        </script>

In HTML:

<input type="button" value="Print Div" onclick="PrintElem('divName')" />

Problem statement:

The dygraph ("divName"), contains a script which plots the actual chart in HTML. The print function can not cater for this when trying to print the innerHTML.

Is there another way to do this? Thanks!