簡體   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