Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize a chart before printing with Highcharts

I have a chart without height or width.

When I click on the print button, I want to obtain a taller and larger graph. I tried setSize() but since I don't know the original size of my graph (because there is not), I can't resize it like it was before and I end up with an enormous graph. I also tried to create a copy of the chart (by changing the renderTo, width and height attributes) inside another div but didn't suceed. It's been several hours and i'm all confused.

What should i do to stretch my graph in order to print it without modifing the original one ?

Thanks for your help.

like image 893
Grégoire Borel Avatar asked Feb 16 '23 10:02

Grégoire Borel


1 Answers

Pawel's Fiddle doesn't work on IE, which does the second setSize before the printing. You need to set a timeout for the size to occur after the printing.

This works fine : http://jsfiddle.net/6hyfk/34/

$('#container').highcharts({
    series: [{

        data: [1, 2, 3]        
    }]
});

$("#b").click(function() {
    var chart = $('#container').highcharts();

    chart.setSize(200,500, false);
    chart.print();
    setTimeout(function() {
        chart.setSize(600,500, false);
    }, 1000);

});
like image 65
Arthur Ouaki Avatar answered Feb 18 '23 00:02

Arthur Ouaki