Reputation: 147
I am trying to trigger click automatically after the page load. Here is the code
$("document").ready(function() {
setTimeout(function() {
$(".amcharts-export-menu-top-right").find('a').trigger('click');
},1000);
});
But it is not working
Here is the entire code: https://jsfiddle.net/32g26a4d/
Upvotes: 1
Views: 2988
Reputation: 16012
You should do this during the chart's rendered
or animationFinished
event if you have an animation. $("document").ready()
doesn't ensure that the chart will be finished loaded as the chart creation process is asynchronous.
Add this to your makeChart call:
//if you have startDuration set to a value > 0:
AmCharts.makeChart("chartdiv", {
// ...
"listeners": [{
"event": "animationFinished",
"method": function() {
$('.amcharts-main-div .amcharts-export-menu-top-right a')[0].dispatchEvent(new Event('click'));
}
}]
});
//if you don't have startDuration set or it is set to 0:
AmCharts.makeChart("chartdiv", {
// ...
"listeners": [{
"event": "rendered",
"method": function() {
setTimeout(function() {
$('.amcharts-main-div .amcharts-export-menu-top-right a')[0].dispatchEvent(new Event('click'));
}, 500)
}
}]
});
Upvotes: 0
Reputation: 4674
As you are using .export-main
class for creating button using AmCharts you don't need to use any other class/find method for selecting that anchor
button. Please follow below code::
$("document").ready(function() {
setTimeout(function() {
$(".export-main a")[0].click();
},1000);
});
Working jsfiddle link:: link
Upvotes: 0