gpt4 book ai didi

firefox - 谷歌图表 : google is not defined

转载 作者:行者123 更新时间:2023-12-04 17:56:25 24 4
gpt4 key购买 nike

我正在尝试在 Firefox 上使用 google 图表,问题是 google api 未在 Firefox 上成功加载 ReferenceError: google is not defined
这是我的代码:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
function LoadGoogle(){
if(typeof google != 'undefined' && google && google.load){
google.charts.load('current', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);

// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
}
else
{
console.log("try");
setTimeout(LoadGoogle, 30);
}
}

LoadGoogle();
</script>

最佳答案

第一 , 删除对 jsapi 的引用,如 release notes 中所述...

The version of Google Charts that remains available via the jsapi loader is no longer being updated consistently. Please use the new gstatic loader (loader.js) from now on.



下一个 , 删除“验证” if声明来自 LoadGoogle ,这不应该是必需的,并且由于删除 jsapi 而需要更改

以下代码段适用于我在 Firefox ESR, v: 45.3.0

function LoadGoogle(){
google.charts.load('current', {
callback: drawChart,
packages:['corechart']
});

function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);

var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};

var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
}

LoadGoogle();
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

关于firefox - 谷歌图表 : google is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40201006/

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