Highcharts在打印前删除主题背景

时间:2013-08-06 12:19:38

标签: jquery highcharts highstock

我有一个很大的Highstock图表,应用了“灰色”主题。用户可以通过按下自定义按钮来打印此图表。我想要的是在打印图表之前删除主题的背景gradiënt(或图像?),因为我们需要打印带有白色背景的图表。

我想我需要删除图表的背景,打印图表,然后重新应用背景。

有人知道怎么做吗?

这是我到目前为止所做的:

 $(document).on("click", "#btnPrintChart", function (event) {
        var chart = $('#container').highcharts();

        chart.backgroundColor = null; //not working
        chart.plotBackgroundImage = null; //not working
        chart.plotBackgroundColor = '#C0C0C0'; //not working
        chart.redraw();

        //Resize chart to fit paper
        chart.setSize(1000, 600, false);
        chart.print();
    });

1 个答案:

答案 0 :(得分:1)

不幸的是,不支持这样的事情。您所能做的就是操纵现有对象:http://jsfiddle.net/Fusher/3bQne/314/

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        plotBackgroundImage: 'http://highcharts.com/demo/gfx/skies.jpg',
        plotBackgroundColor: {
            linearGradient: [0, 0, 250, 500],
            stops: [
                [0, 'rgba(255, 255, 100, 1)'],
                [1, 'rgba(255, 255, 100, 0)']
            ]
        }
    },
    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0]
    }]
});

$("#b").click(function () {
    chart.plotBGImage.hide();
    chart.print();
    chart.plotBGImages.show();
});