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?
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();
}
}
}
});
});
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