score:21
indeed the delayed call is not a very good approach. the load
event is working properly, but the current chart is referred by the this
keyword, i.e.
// create the chart
var chart = new highcharts.chart({
chart: {
renderto: 'container',
events: {
load: function(event) {
//when is chart ready?
console.log(this); //this refers to the loaded chart.
}
}
},
xaxis: {
},
series: [{
animation: false,
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]
}]
});
hope this helps :)
score:3
this is definitely less elegant than the accepted answer, but still works fine with a few lines of code. the essence is to simply poll all chart container html elements.
the code below assumes you have one or more highcharts attached to elements having class="chart":
var chartstoload = [];
$('.chart').each(function(n,elem) {
chartstoload[n] = window.setinterval(function() {
if(typeof($(elem).highcharts()) !== 'undefined') {
// it's loaded now, go ahead...
$(elem).highcharts().dosomehighchartsstuffhere()
// permanently stop polling
window.clearinterval(chartstoload[n]);
}
}, 100); // check every 100ms
});
score:6
the highcharts.chart constructor takes a callback argument that is called "when the chart object is finished loading and rendering". the chart object is passed as an argument to the callback.
$("#the-chart").highcharts(options, function (chart) {
alert("the chart is ready now");
console.log("chart", chart);
});
chart (object options, function callback) this is the constructor for creating a new chart object.
parameters
options: object
the chart options, as documented under the heading "the options object"in the left menu.callback: function
a function to execute when the chart object is finished loading and rendering. in most cases the chart is built in one thread, but in internet explorer version 8 or lessthe chart is sometimes initiated before the document is ready, and in thesecases the chart object will not be finished directly after callingnew highcharts.chart(). as a consequence, code that relies on the newly built chart object should always run in the callback. defining a chart.event.load handler is equivalent.returns
- chart
Source: stackoverflow.com
Related Query
- Strange character in the Highstock source code
- Highcharts - manually trigger hover event on a point
- How do I detect a zoom event in highcharts?
- Highcharts's onReady event?
- How do I add an event listener to a Highcharts object *AFTER* I've created it
- Highcharts - fire legendItemClick event
- Highcharts - Double click event
- Highcharts chart click event fired on click of the reset zoom button (bug?)
- Optimize JavaScript DrillDown code
- programmatically trigger click event in svg rect element
- ReactErrorUtils.invokeGuardedCallback in React fires event repeatedly in IE browser
- Highcharts : Chart with drilldown how to obtain click event of drill up button
- Click event on clicking on the graph
- highcharts how to catch and insert logic in click reset zoom button event
- highmaps get country name on click event
- Append onload or redraw event functions dynamically in Highcharts
- In high chart how to add event for label click
- programatically fire a click event for a point on highchart scatter plot
- React plot options onclick event
- How to pass custom data into Highcharts graph click event
- Replacing highcharts.each in my code as it is being deprecated
- How to setExtremes in xAxis event handler?
- how to get chart object inside a point event function in Highcharts
- Access props and state of current component in React JS within an event handler
- Trigger an event when i scroll the scrollbar in highchart?
- Get X Axis value on bar Highchart click event
- Add onclick event on chart made with the highcharts library
- how to handle mouse over event in legend in highcharts?
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- Code works on fiddle but not when I do /show
More Query from same tag
- fix a number of labeles on xAxis highcharts
- Highcharts data grouping method for objects
- Highcharts bar border
- Series name with series color at the end of line series
- Highcharts piechart labels going out of parent
- In Vue JS, assign data from mounted()
- Use High-charts, Open Flash Chart 2, Google Charts or what else !
- remove Highchart.com link from the chart
- Highchart Change lineWidth of a Serie
- HghCharts drilldown module: Uncaught TypeError: Cannot read property 'lang' of undefined
- highcharts 5.0.14 phantomjs issue with missing axis titles in exported image
- Highcharts not working in UpdatePanel of asp.net
- Highcharts display label for pie chart using html table as data source
- Highcharter format number in tooltip
- Highcharts Gauge Spacing
- Limiting the Highcharts x Axis while the chart extending During Ajax Drill Down
- How to elegantly plot charts in ASP.NET MVC 3 using Highcharts?
- Highstock month dataGrouping with Jalali/Persian dates
- Highstock graph is not showing when only single data is present
- Is it possible in highcharts to have 2 charts, sharing the same x-axis, but next to one another?
- How can I show colorAxis color in Highcharts legend as series color?
- highchart map create marker by click and get lat long coordinates
- Highcharts Polar Chart customization
- highcharts add plotline label with images
- How can I create a daily chart with HighCharts
- Rails Not outputting Highcharts javascript graph
- Highcharts datalabel formatter for export server
- hide zoom text on rangeSelector
- How do I create a break on the x-axis with highcharts?
- Gauge highcharts is not resize with ionic 2