Can not exporting renderer shapes added in callback function in highcharts / highstock

走远了吗. 提交于 2019-11-28 12:35:41

问题


I want to dynamically added several primitive shapes like text and images into highcharts / highstock.

Please see this fiddle.

$(function () {
    var chart = new Highcharts.Chart({

        chart: {
            renderTo: 'container',
            spacingBottom: 50
        },

        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },

        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]
    }, function(chart) { // on complete
        $("#add").click(function(){
    chart.renderer.image('http://highcharts.com/demo/gfx/sun.png', 100, 100, 30, 30)
        .add();   
        });
});
});

After click button "Add Image", there is a image will be added to chart. Unfortunately, those dynamically added elements can not be exported to images.

Is there any possible solution to fix this?


回答1:


You can use chart.exportChart() function to achieve that: http://jsfiddle.net/B6s7V/38/

The same solution as here.

$("#export").click(function () {
    chart.exportChart(null, {
        chart: {
            events: {
                load: function () {
                    this.renderer.image('http://highcharts.com/demo/gfx/sun.png', 100, 100, 30, 30).add();
                }
            }
        }
    });
});



回答2:


When you export a chart, the chart SVG is regenerated from the original .Chart call. If you want to add things after the chart has drawn, do it in the charts:events:load callback.

    chart: {
        renderTo: 'container',
        spacingBottom: 50,
        events: {
            load: function(){
                this.renderer.image('http://highcharts.com/demo/gfx/sun.png', 100, 100, 30, 30).add();
            }
        }
    }, 

See updated fiddle here.



来源:https://stackoverflow.com/questions/16508849/can-not-exporting-renderer-shapes-added-in-callback-function-in-highcharts-hig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!