gpt4 book ai didi

javascript - amCharts 4 CDN 网::ERR_FILE_NOT_FOUND

转载 作者:行者123 更新时间:2023-12-03 00:08:57 28 4
gpt4 key购买 nike

我正在尝试测试发现的 amCharts 4 Javascript 示例代码 here但我在控制台中收到以下错误:

charts.html:9 GET file://www.amcharts.com/lib/4/core.js net::ERR_FILE_NOT_FOUND
charts.html:10 GET file://www.amcharts.com/lib/4/charts.js net::ERR_FILE_NOT_FOUND
charts.html:11 GET file://www.amcharts.com/lib/4/maps.js net::ERR_FILE_NOT_FOUND
charts.html:17 Uncaught ReferenceError: am4core is not defined
at charts.html:17

我已在 Google Chrome(版本 72.0.3626.119)和 Firefox 中尝试过,但都产生相同的结果。页面无法定位CDN并显示图表。

访问链接时,一切似乎都是正确的,因此这似乎不是问题。我还下载了文件并尝试在本地连接,再次产生相同的结果。

下面的代码片段按预期运行,并毫无问题地显示饼图,但在 Chrome 或 Firefox 中打开它时,它对我不起作用。

如有任何建议,我们将不胜感激。

这是代码:

<!DOCTYPE html>
<html>
<head>
<title>AMCharts Example</title>

<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>

</head>
<body>

<div id="chartdiv" style="width: 900px; height: 800px;"></div>

<script>
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.PieChart);

// Create pie series
var series = chart.series.push(new am4charts.PieSeries());
series.dataFields.value = "litres";
series.dataFields.category = "country";

// Add data
chart.data = [{
"country": "Lithuania",
"litres": 501.9
}, {
"country": "Czech Republic",
"litres": 301.9
}, {
"country": "Ireland",
"litres": 201.1
}, {
"country": "Germany",
"litres": 165.8
}, {
"country": "Australia",
"litres": 139.9
}, {
"country": "Austria",
"litres": 128.3
}, {
"country": "UK",
"litres": 99
}, {
"country": "Belgium",
"litres": 60
}, {
"country": "The Netherlands",
"litres": 50
}];

// And, for a good measure, let's add a legend
chart.legend = new am4charts.Legend();
</script>

</body>
</html>

按照 Daniel 的建议,更改脚本 src 标记以包含 https 协议(protocol)后,我收到以下错误:

core.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
charts.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
maps.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
charts.html:17 Uncaught ReferenceError: am4core is not defined
at charts.html:17

最佳答案

您正在 <script> 中使用协议(protocol)相对路径标签,但 404 错误显示 file:// URL 上的协议(protocol),这表明您正在从 file:// 进行测试URL 而不是来自真实的 Web 服务器。

(从实时服务器测试时,问题中发布的代码工作正常):

// Create chart instance
var chart = am4core.create("chartdiv", am4charts.PieChart);

// Create pie series
var series = chart.series.push(new am4charts.PieSeries());
series.dataFields.value = "litres";
series.dataFields.category = "country";

// Add data
chart.data = [{
"country": "Lithuania",
"litres": 501.9
}, {
"country": "Czech Republic",
"litres": 301.9
}, {
"country": "Ireland",
"litres": 201.1
}, {
"country": "Germany",
"litres": 165.8
}, {
"country": "Australia",
"litres": 139.9
}, {
"country": "Austria",
"litres": 128.3
}, {
"country": "UK",
"litres": 99
}, {
"country": "Belgium",
"litres": 60
}, {
"country": "The Netherlands",
"litres": 50
}];

// And, for a good measure, let's add a legend
chart.legend = new am4charts.Legend();
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>

<div id="chartdiv" style="width: 900px; height: 800px;">
</div>

要么在本地主机上测试你的代码,要么切换那些 <script>标签使用完整 https:// (或 http:// )协议(protocol)。

<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>

关于javascript - amCharts 4 CDN 网::ERR_FILE_NOT_FOUND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54833392/

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