Search code examples
google-chromechartshighchartscontextmenucorrupt

Highcharts context menu causes chart to disappear on return from print screen only on Chrome


We are using Highcharts 4.0.4 and PHP as the server side script. There are multiple charts on a page and each chart has its context menu for print/save options.

The context menu works fine, but when control returns from the print screen to the page, the respective chart is either corrupted in size or disappears altogether.

Strangely this bad behavior is observed only on Chrome but not IE.

A fiddle demonstrating this behavior.

Code along with fiddle

Any help or guidance on how to tackle this problem is greatly appreciated.


Solution

  • Defaulty in the highcharts all elements are hidden apart of current chart. You can wrap the exporting function and dismiss this part of code.

    (function (H) {
        H.wrap(H.Chart.prototype, 'print', function (proceed) {
            var chart = this,
                container = chart.container,
                origDisplay = [],
                win = window,
                origParent = container.parentNode,
                body = document.body,
                childNodes = body.childNodes;
    
            if (chart.isPrinting) { // block the button while in printing mode
                return;
            }
    
            chart.isPrinting = true;
    
    
            // print
            win.focus(); // #1510
            win.print();
    
            // allow the browser to prepare before reverting
            setTimeout(function () {
    
                // put the chart back in
                origParent.appendChild(container);
    
    
                chart.isPrinting = false;
    
            }, 1000);
    
        });
    })(Highcharts);
    

    Example: http://jsfiddle.net/ND5xf/5/