繁体   English   中英

amCharts 4 CDN net :: ERR_FILE_NOT_FOUND

[英]amCharts 4 CDN net::ERR_FILE_NOT_FOUND

我正在尝试测试在此处找到的amCharts 4 Javascript示例代码但在控制台中出现以下错误:

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> 

在更改脚本src标记以包括https协议之后(如Daniel所建议的那样),我得到以下错误:

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>标记中使用的是协议相对路径,但是404错误在URL上显示了file://协议,这表明您正在从file:// URL而不是从真实的网络进行测试服务器。

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

 // 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> 

可以在localhost上测试代码,或切换那些<script>标记以使用完整的https:// (或http:// )协议。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM