I render a Highcharts chart in a div with id container
like so:
new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
zoomType: 'x'
},
xAxis: {
categories: ['Jan', 'Feb']
},
series: [{
data: [29.9, 71.5]
}]
});
<div id="container" class="chart"></div>
Notice that I haven't captured a reference to the chart object in a variable. At some point after the chart has been rendered is it possible to get a reference to the chart object from the ID of the element it has been rendered to (container
in this case)?
With jQuery
var Mychart=$("#container").data('highchartsChart');
or
var Mychart=$("#container").highcharts();
jsfiddle
or via the Highcharts' charts array ([0] if your chart is the first)
var Mychart = Highcharts.charts[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With