gpt4 book ai didi

javascript - 如何确保在使用图表之前加载它们?

转载 作者:行者123 更新时间:2023-11-28 15:04:44 25 4
gpt4 key购买 nike

我想在运行其余的 javascript 之前加载我的谷歌图表。

$(document).ready(function() {
google.charts.load("current", {packages:["corechart"]});

我最初放入此代码是为了留出一些时间来加载图表,但有时图表花费的时间比预期要长,并且我的代码会中断。 javascript 中是否有可以使用的初始化函数?

setTimeout(function() {
map.setView([gon.locations[3].latitude, gon.locations[3].longitude - .01],15);
if(typeof lastMarker !== "undefined")
map.removeLayer(lastMarker);
$('progress').animate({value: gon.locations[3].overall_vulnerability}, {duration: 1000});
$('#vul').html(gon.locations[3].overall_vulnerability);
var markers = L.mapbox.featureLayer().setGeoJSON(getData(gon.locations[3])).addTo(map);
google.charts.setOnLoadCallback(drawChart(gon.locations[3]));
openNav();
lastMarker = markers;
}, 1500);

最佳答案

这就是 setOnLoadCallback() 函数的用途 - 它在加载完成时运行。

google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(function() {
// Everything you want to happen after loading goes here
});

来自 documentation :

Before you can use any of the packages loaded by google.charts.load you have to wait for the loading to finish. It is not enough to just wait for the document to finish loading. Since it can take some time before this loading is finished, you need to register a callback function.

关于javascript - 如何确保在使用图表之前加载它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39516131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com